Commit 63ade4dc authored by Mihkel Putrinš's avatar Mihkel Putrinš

render resource stats

parent 3a0b5c98
......@@ -3,6 +3,7 @@ var op = require('object-path')
var fs = require('fs')
var ipc = require('ipc')
BrowserWindow = require('browser-window')
var j = require('electron-jade')({pretty: true}, {})
var user_url = 'https://entu.keeleressursid.ee/api2/user'
var auth_url = user_url + '/auth'
......@@ -13,7 +14,6 @@ var user_data = {}
app.on('ready', function() {
authWindow = new BrowserWindow({ width: 300, height: 600, show: true })
authWindow.setTitle('Panustaja - log in')
// authWindow.loadUrl('http://ww.ee')
authWindow.loadUrl(auth_url)
authWindow.webContents.on('did-finish-load', function() {
authWindow.webContents.savePage('./user.json', 'HTMLOnly', function(err) {
......@@ -41,7 +41,7 @@ app.on('ready', function() {
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true })
mainWindow.setTitle('Panustaja - ' + user_data['name'])
mainWindow.center()
mainWindow.loadUrl('file://' + __dirname + '/main.html')
mainWindow.loadUrl('file://' + __dirname + '/views/main.jade')
authWindow.close()
mainWindow.webContents.openDevTools(true)
......@@ -56,7 +56,7 @@ app.on('ready', function() {
})
ipc.on('log', function(event, message) {
console.log('message: ' + message)
console.log('message: ', message)
})
ipc.on('data', function(event, message) {
console.log('data: ' + JSON.stringify(message, null, 4))
......
var bytesToSize = function bytesToSize(bytes) {
if (bytes === undefined) bytes = 0
var sizes = ['B', 'KB', 'MB', 'GB', 'TB']
......
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css"> -->
</head>
<body>
<h1 id="user_name">Panustaja</h1>
<input id="resource_name" type="text" placeholder="Ressursi nimi" style="width:100%;" hidden></input>
<div id="contents">
<div>Palun vali fail või kataloog, mida soovid üles laadida.</div>
<button id="selectLocal" onclick="selectLocal();">Vali fail</button>
</div>
<script src='./main.js'></script>
</body>
</html>
......@@ -3,12 +3,10 @@ var fs = require('fs')
var op = require('object-path')
var path = require('path')
var async = require('async')
var mime = require('mime-types')
// TODO: WATCH: mmmagic is broken currently: Module version mismatch. Expected 46, got 14
// var Magic = require('mmmagic').Magic
// var magic = new Magic(mmm.MAGIC_MIME_TYPE | mmm.MAGIC_MIME_ENCODING)
// usage: magic.detectFile(_path, function(err, result) {
var mmm = require('mmmagic')
var Magic = mmm.Magic
var magic = new Magic(mmm.MAGIC_MIME_TYPE | mmm.MAGIC_MIME_ENCODING)
var remote = require('remote')
var dialog = remote.require('dialog')
......@@ -16,19 +14,22 @@ var dialog = remote.require('dialog')
var ipc = require('ipc')
ipc.send('userdata-query')
ipc.on('userdata-reply', function(user_data) {
document.getElementById('user_name').innerHTML = user_data.name
document.getElementById('userName').innerHTML = user_data.name
})
var b2s = require(path.join(__dirname, '..', 'bytesToSize.js'))
var resource = {}
var resource_stats = {}
var dom_resource_name = document.getElementById('resource_name')
var dom_resource_name = document.getElementById('resourceName')
var dom_resource_stats = document.getElementById('resourceStats')
dom_resource_name.setAttribute('hidden', '')
function selectLocal () {
resource = {name: 'root'}
resource_stats = {files: 0, directories: 0, mime:{}}
resource_stats = {files: {count: 0, size: 0}, directories: {count: 0}, mime:{}}
dialog.showOpenDialog({properties:['openFile', 'openDirectory', 'multiSelections']}, function selectedPath(_paths) {
dom_resource_name.removeAttribute('hidden')
setFormState('loading')
dom_resource_name.value = ''
if (_paths.length === 1) {
var single_file = _paths[0]
......@@ -45,53 +46,85 @@ function selectLocal () {
}
_paths = files.map(function(file) {
var fullpath = path.join(single_file, file)
console.log('foo1', single_file + '+' + file + '=' + fullpath)
// console.log('foo1', single_file + '+' + file + '=' + fullpath)
return fullpath
})
console.log('foo1');
recurseLocal(resource, _paths, resourceLoaded)
})
} else {
console.log('foo2');
recurseLocal(resource, _paths, resourceLoaded)
}
})
} else {
console.log('foo3');
recurseLocal(resource, _paths, resourceLoaded)
}
})
}
var resourceLoaded = function resourceLoaded() {
console.log(JSON.stringify(resource, null, 4))
console.log(JSON.stringify(resource_stats, null, 4))
setFormState('select')
console.log(JSON.stringify(b2s(resource_stats.files.size), null, 4))
console.log(resource_stats.files.size)
ipc.send('data', resource_stats)
renderResource()
}
var renderResource = function renderResource() {
dom_resource_stats.removeAttribute('hidden')
document.getElementById('resourceDirectories').innerHTML = ''
document.getElementById('resourceFiles').innerHTML = ''
document.getElementById('mimeStats').innerHTML = ''
document.getElementById('resourceDirectories').appendChild(document.createTextNode('Katalooge: ' + resource_stats.directories.count))
document.getElementById('resourceFiles').appendChild(document.createTextNode('Faile: ' + resource_stats.files.count + ' / ' + b2s(resource_stats.files.size)))
Object.keys(resource_stats.mime).forEach(function (mime_type_name) {
var text_node = document.createTextNode(
mime_type_name
+ ': ' + op.get(resource_stats, ['mime', mime_type_name, 'count'])
+ ' / ' + b2s(op.get(resource_stats, ['mime', mime_type_name, 'size']))
)
var li_node = document.createElement('LI')
li_node.appendChild(text_node)
document.getElementById('mimeStats').appendChild(li_node)
})
}
var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) {
console.log(JSON.stringify(paths, null, 4))
// console.log(JSON.stringify(paths, null, 4))
async.each(paths, function iterator(_path, callback) {
fs.stat(_path, function(err, stats) {
console.log('stats for:', _path)
if (err) {
// console.log(err)
return callback()
}
if (stats.isFile()) {
resource_stats.files ++
op.push(parent_resource, 'files', _path)
var mimetype = mime.lookup(_path) || 'unknown'
op.set(resource_stats, ['mimetypes', mimetype], op.get(resource_stats, ['mimetypes', mimetype], 0) + 1)
console.log('file', _path, mimetype)
callback()
magic.detectFile(_path, function(err, result) {
if (err) {
// console.log(err)
return callback()
}
resource_stats.files.count++
resource_stats.files.size += stats.size
op.push(parent_resource, 'files', _path)
var mime = result.split(';')[0]
var charset = result.split(';')[1].split('=')[1]
op.set(resource_stats, ['mime', mime, 'count'], op.get(resource_stats, ['mime', mime, 'count'], 0) + 1)
op.set(resource_stats, ['mime', mime, 'size'], op.get(resource_stats, ['mime', mime, 'size'], 0) + stats.size)
op.set(resource_stats, ['mime', mime, 'charsets', charset, 'count'], op.get(resource_stats, ['mime', mime, 'charsets', charset, 'count'], 0) + 1)
op.set(resource_stats, ['mime', mime, 'charsets', charset, 'size'], op.get(resource_stats, ['mime', mime, 'charsets', charset, 'size'], 0) + stats.size)
callback()
})
} else if (stats.isDirectory()) {
resource_stats.directories ++
resource_stats.directories.count++
var directory = {name: _path}
op.push(parent_resource, 'resources', directory)
console.log('dir: ' + JSON.stringify(_path, null, 4))
// console.log('dir: ' + JSON.stringify(_path, null, 4))
fs.readdir(_path, function(err, files) {
if (err) {
return callback(err)
}
var _paths = files.map(function(file) {
var fullpath = path.join(_path, file)
console.log(_path + '+' + file + '=' + fullpath)
// console.log(_path + '+' + file + '=' + fullpath)
return fullpath
})
recurseLocal(directory, _paths, callback)
......@@ -106,3 +139,21 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) {
}
})
}
var setFormState = function setFormState(state) {
switch(state) {
case 'select':
document.getElementById('loading').setAttribute('hidden', '')
document.getElementById('resourceStats').removeAttribute('hidden')
document.getElementById('selectLocal').removeAttribute('hidden')
document.getElementById('selectLocalMessage').removeAttribute('hidden')
break
case 'loading':
dom_resource_name.removeAttribute('hidden')
document.getElementById('loading').removeAttribute('hidden')
document.getElementById('resourceStats').setAttribute('hidden', '')
document.getElementById('selectLocal').setAttribute('hidden', '')
document.getElementById('selectLocalMessage').setAttribute('hidden', '')
break
}
}
doctype html
html
head
meta(charset='utf-8')
link(rel='stylesheet', type='text/css', href='../style/style.css')
link(rel='icon' type='image/png', href='/favicon-96x96.png' sizes='96x96')
link(rel='shortcut icon', href='/favicon.ico')
body
h1#userName Panustaja
div#selectLocalMessage Palun vali fail või kataloog, mida soovid üles laadida.
button#selectLocal(onclick='selectLocal()') Vali fail
input#resourceName(type='text' placeholder='Ressursi nimi' style='width:100%;' hidden='')
div#contents
h3#loading(hidden='') Loading...
ul#resourceStats(hidden='')
li#resourceDirectories
li#resourceFiles
ul#mimeStats
script(src='../main.js')
var app = require('app')
var fs = require('fs')
var ipc = require('ipc')
var BrowserWindow = require('browser-window')
var onlineStatusWindow
var user_url = 'https://entu.keeleressursid.ee/api2/user'
var auth_url = user_url + '/auth'
app.on('ready', function() {
authWindow = new BrowserWindow({ width: 900, height: 600, show: true })
authWindow.loadUrl(auth_url)
console.log('ready')
authWindow.webContents.savePage('./user.json', 'HTMLOnly', function(err) {
if (err) {
console.log("err", err)
} else {
console.log("Save page successfully")
fs.readFile('./user.json', 'utf8', function(err, data) {
console.log( JSON.stringify(JSON.parse(data), null, 4))
fs.unlink('./user.json', function (err) {
if (err) throw err
console.log('successfully deleted user.json')
})
})
}
})
})
ipc.on('online-status-changed', function(event, status) {
console.log(status)
})
ipc.on('message', function(event, message) {
// console.log('event: ' + JSON.stringify(event, null, 4))
console.log('message: ' + message)
})
ipc.on('user', function(event, data) {
// console.log('event: ' + JSON.stringify(event, null, 4))
console.log('data: ' + JSON.stringify(data, null, 4))
})
47c47
< <string>node-webkit</string>
---
> <string>Panustaja</string>
51c51
< <string>30.0.1599.66</string>
---
> <string>1.0.0-rc.1</string>
53c53
< <string>1599.66</string>
---
> <string>Release Candidate</string>
var NwBuilder = require('node-webkit-builder')
var nw = new NwBuilder({
files: [
'../node_modules/**',
'../source/**',
'../package.json'
], // use the glob format
// platforms: ['osx64'],
platforms: ['linux'],
buildDir: '../bin',
cacheDir: '../../../nwbuilder/cache',
version: '0.8.6',
macZip: true,
appVersion: true,
macIcns: '../EKRK/uploader/source/images/murakas.icns'
})
//Log stuff you want
nw.on('log', console.log)
// Build returns a promise
nw.build().then(function () {
console.log('all done!')
}).catch(function (error) {
console.error(error)
})
#!/bin/sh
# Make osx32
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )
cd ${DIR}
workingDir="${DIR}/bin/osx32"
applicationName="Panustaja.app"
DMGName="${DIR}/bin/temp.dmg"
finalDMGName="${DIR}/bin/Panustaja.dmg"
sizeOfDmg="200M"
diskTitle="Panustaja installer"
nwAppPath="${workingDir}/${applicationName}"
backgroundPictureName="arrow.png"
rm -rf "${workingDir}" "${finalDMGName}"
mkdir -p "${workingDir}"
cp -r "${DIR}/source" "${workingDir}"
# cp -r "${DIR}/imgs" "${workingDir}"
cp -r "${DIR}/node_modules" "${workingDir}"
cp -r "${DIR}/index.html" "${workingDir}"
cp -r "${DIR}/package.json" "${workingDir}"
cp -r "${DIR}/LICENSE.md" "${workingDir}"
pushd "${workingDir}"
zip -r ../app.nw ./*
rm -r *
popd
cp -r "${DIR}/../../nwbuilder/cache/0.8.6/osx32/node-webkit.app" "${nwAppPath}"
# cp "${DIR}/ffmpegsumo for 0.8.6/ffmpegsumo.so" "${nwAppPath}/Contents/Frameworks/node-webkit Framework.framework/Libraries/"
mv "${DIR}/bin/app.nw" "${nwAppPath}/Contents/resources/"
cp "${DIR}/source/images/murakas.icns" "${nwAppPath}/Contents/resources/nw.icns"
# Replace information in Node-Webkit's Info.plist
patch "${nwAppPath}/Contents/Info.plist" "make/info_plist.patch"
# Create a R/W DMG
hdiutil create -srcfolder "${workingDir}" -volname "${diskTitle}" \
-fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${sizeOfDmg} "${DMGName}"
# Mount the image
device=$(hdiutil attach -readwrite -noverify -noautoopen "${DMGName}" | \
egrep '^/dev/' | sed 1q | awk '{print $1}')
# Prepare for ascript
pushd "/Volumes/${diskTitle}"
mkdir -p .background
cp "${DIR}/make/${backgroundPictureName}" .background
popd
# Run ascript
echo '
tell application "Finder"
tell disk "'${diskTitle}'"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 100, 885, 330}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 72
set background picture of theViewOptions to file ".background:'${backgroundPictureName}'"
make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
set position of item "'${applicationName}'" of container window to {100, 100}
set position of item "Applications" of container window to {375, 100}
update without registering applications
delay 5
close
end tell
end tell
' | osascript
chmod -Rf go-w "/Volumes/${diskTitle}"
sync
hdiutil detach ${device}
hdiutil convert "${DMGName}" -format UDZO -imagekey zlib-level=9 -o "${finalDMGName}"
rm -f "${DMGName}"
rm -rf "${workingDir}"
#!/bin/sh
# Make win32
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )
cd ${DIR}
diskTitle="Panustaja"
workingDir="${DIR}/bin/${diskTitle}"
rm -rf "${workingDir}"
mkdir -p "${workingDir}"
cp -r "${DIR}/source" "${workingDir}"
cp -r "${DIR}/node_modules" "${workingDir}"
cp -r "${DIR}/package.json" "${workingDir}"
cp -r "${DIR}/LICENSE.md" "${workingDir}"
pushd "${workingDir}"
echo "zip -r ../app.nw ./*"
zip -r ../app.nw ./*
rm -r *
popd
cp "${DIR}/../../nwbuilder/cache/0.12.2/win32/icudtl.dat" "${workingDir}"
cp "${DIR}/../../nwbuilder/cache/0.12.2/win32/libEGL.dll" "${workingDir}"
cp "${DIR}/../../nwbuilder/cache/0.12.2/win32/libGLESv2.dll" "${workingDir}"
cp "${DIR}/../../nwbuilder/cache/0.12.2/win32/nw.exe" "${workingDir}"
cp "${DIR}/../../nwbuilder/cache/0.12.2/win32/nw.pak" "${workingDir}"
echo "cat \"${workingDir}/nw.exe\" \"${DIR}/bin/app.nw\" > \"${workingDir}/Panustaja.exe\""
cat "${workingDir}/nw.exe" "${DIR}/bin/app.nw" > "${workingDir}/Panustaja.exe"
rm -f "${workingDir}/nw.exe" "${DIR}/bin/app.nw"
# pushd "${DIR}/bin"
# zip -r "panustaja_win32".zip "${diskTitle}"/*
# popd
# cat "${DIR}/make/unzipsfx.exe" "${DIR}/bin/panustaja_win32.zip" > "${DIR}/bin/panustaja_setup.exe"
# zip -A "${DIR}/bin/panustaja_setup.exe"
echo '
tell application "Finder"
tell disk "Screenwerk"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 100, 885, 430}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 72
set background picture of theViewOptions to file ".background:'${backgroundPictureName}'"
make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
set position of item "'${applicationName}'" of container window to {100, 100}
set position of item "Applications" of container window to {375, 100}
update without registering applications
delay 5
close
end tell
end tell
' | osascript
\ No newline at end of file
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{B2A00D3D-669C-4305-A22C-002D647E5E1A}
AppName=Panustaja
AppVersion=1.0.0
AppVerName=Panustaja 1.0.0
AppPublisher=ekrk
DefaultDirName={pf}\Panustaja
DisableDirPage=yes
DefaultGroupName=Panustaja
DisableProgramGroupPage=yes
OutputDir=Y:\EKRK\uploader\bin
OutputBaseFilename=setup
SetupIconFile=Y:\EKRK\uploader\source\images\murakas.ico
Compression=lzma
SolidCompression=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
[Files]
Source: "Y:\EKRK\uploader\bin\Panustaja\Panustaja.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "Y:\EKRK\uploader\bin\Panustaja\icudtl.dat"; DestDir: "{app}"; Flags: ignoreversion
Source: "Y:\EKRK\uploader\bin\Panustaja\nw.pak"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\Panustaja"; Filename: "{app}\Panustaja.exe"
Name: "{group}\{cm:UninstallProgram,Panustaja}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\Panustaja"; Filename: "{app}\Panustaja.exe"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\Panustaja"; Filename: "{app}\Panustaja.exe"; Tasks: quicklaunchicon
[Run]
Filename: "{app}\Panustaja.exe"; Description: "{cm:LaunchProgram,Panustaja}"; Flags: nowait postinstall skipifsilent
......@@ -11,8 +11,9 @@
},
"dependencies": {
"async": "^1.5.0",
"electron-jade": "^1.3.0",
"marked": "^0.3.5",
"mime-types": "^2.1.7",
"mmmagic": "^0.4.1",
"moment": "^2.10.6",
"object-path": "^0.9.2",
"request": "^2.65.0"
......
{
"__UPLOAD_QUOTA_20G": 21474836480,
"__UPLOAD_QUOTA_100G": 107374182400,
"__MAX_FILESIZE_1G": 1073741824,
"__MAX_FILESIZE_2G": 2147483648,
"__MAX_FILESIZE_4G": 4294967296,
"__CONTACT_EMAIL": "info@keeleressursid.ee",
"__CONTACT_PHONE": "+372 5656 0978",
"__ROOT_EID": 1952,
"__EXCLUDE_FILENAMES": [
".DS_Store",
".dropbox",
".dropbox.cache",
"Icon\r",
"Picasa.ini",
".svn",
".git",
".bin"
]
}
\ No newline at end of file
var gui = window.require('nw.gui')
module.exports.decorate = function decorate() {
var win = gui.Window.get()
var nativeMenuBar = new gui.Menu({ type: "menubar" })
try {
nativeMenuBar.createMacBuiltin(gui.App.manifest.name + ' ' + gui.App.manifest.version, {
// hideEdit: true,
hideWindow: true
})
nativeMenuBar.items[0].label = 'Panustaja'
win.menu = nativeMenuBar
win.menu.items[0].icon = 'source/images/pixel.png'
win.menu.items[0].submenu.items[0].icon = 'source/images/minimura.png'
win.menu.items[0].submenu.items[0].label = 'Panustajast...'
} catch (ex) {
console.log(ex.message)
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Keeleressurside Panustaja</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="../node_modules/font-awesome/css/font-awesome.min.css">
<link href="style.css" rel="stylesheet" />
<script type="text/javascript" src="../node_modules/jquery/dist/jquery.js"></script>
<script src="./script.js" charset="utf-8"></script>
</head>
<body>
<input id="chdir_input" type="file" nwdirectory style="display:none" />
<div>
<table id="cards">
<tr>
<td id="hello_card_label" translate="hello_card" class="card_title current">Hello</td>
<td id="select_card_label" translate="select_card" class="card_title">Select</td>
<td id="upload_card_label" translate="upload_card" class="card_title">Upload</td>
<td id="thankyou_card_label" translate="thankyou_card" class="card_title">Thank You</td>
</tr>
<tr>
<td colspan="4">
<div id="card_contents" style="overflow: auto; height:800px">
<card id="hello_card">
<div translate="hello_text" class="infotext"></div>
<button id="login_button" translate="login_button">.</button>
</card>
<card id="select_card">
<div translate="select_text" class="infotext"></div>
<button id="chdir_button">.</button>
</card>
<card id="upload_card">
<div translate="upload_text" class="infotext"></div>
<div id="upload_stats"></div>
<label translate="resource_name">resource_name</label>
<input id="resource_name" />
<div id="overquota_total" translate="overquota_total" class="warning">
</div>
<div id="overquota_files" class="warning">
</div>
<button id="back_button" style="display:inline;" translate="back_button">.</button>
<button id="upload_button" style="display:inline;" translate="upload_button">.</button>
<div id="local_fs_tree"></div>
</card>
<card id="thankyou_card">
<div translate="thankyou_text" class="infotext">
</div>
</card>
<div id="uploaded_resource_list" style="display:none" translate="uploaded_resource_list"></div>
</div>
</td>
</tr>
</table>
<div id="waitspinner"></div>
<div id="upload_progress">
<div id="upload_back" progress></div>
<div id="upload_front" progress></div>
</div>
</div>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
var msToDate = function msToDate(ms, without_time) {
if (isNaN(ms)) ms = 0
try {
d = new Date(ms)
if (without_time) {
return d.toISOString().replace(/T/, ' ').replace(/:/g, '-').replace(/\..+/, '').split(' ')[0]
} else {
return d.toDateString() + ' ' + d.toTimeString()
}
} catch (exception) {
console.log('Cant convert "' + ms + '" ms.', d)
throw exception
}
}