Commit 3aa7e582 authored by Mihkel Putrinš's avatar Mihkel Putrinš

build 95. no jade. various improvements

- encourage user to pick a name for resource
- show link to uploaded resource
parent e406bdcf
......@@ -4,7 +4,6 @@ var path = require('path')
var fs = require('fs')
var ipc = require('ipc')
var clipboard = require('clipboard')
var j = require('electron-jade')({pretty: true}, {})
var BrowserWindow = require('browser-window')
var windows = {}
......@@ -52,15 +51,17 @@ app.on('ready', function() {
"partition": "persist:panustaja (build " + (pjson.build) + ")",
"page-visibility": true, // Prevent throttling DOM timers (app gets less priority while in background)
}
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true, "web-preferences": web_preferences })
mainWindow.setTitle('Panustaja')
mainWindow.center()
var view_path = path.join(app.getAppPath(), 'code', 'main.jade')
mainWindow.webContents.loadUrl('file://' + view_path)
setTimeout(function () {
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true, "web-preferences": web_preferences })
mainWindow.setTitle('Panustaja')
mainWindow.center()
var view_path = path.join(app.getAppPath(), 'code', 'main.html')
mainWindow.webContents.loadUrl('file://' + view_path)
if (IS_DEV) {
mainWindow.webContents.openDevTools(true)
}
}, 1000)
windows['authWindow'].hide()
if (IS_DEV) {
mainWindow.webContents.openDevTools(true)
}
} else {
return
}
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
<link rel="shortcut icon" href="/favicon.ico">
</head>
<body>
<h1 id="userName">Tere</h1>
<div id="selectLocal" hidden>
<p id="selectLocalMessage">Palun vali fail(id) ja/või kataloog(id), mida soovid üles laadida.</p>
<button id="selectLocalButton" onclick="selectLocal()">Vali</button>
</div>
<div id="resourceName" hidden="">
<p id="resourceNameMessage">Muuda ressursi nimi sobivaks.</p>
<input id="resourceNameInput" type="text" placeholder="Ressursi nimi" style="width:100%;">
</div>
<div id="loading" hidden="">
<h3>Loen failisüsteemist ...</h3>
</div>
<div id="resourceStats" hidden="">
<ul id="resourceStatsList">
<li id="resourceDirectories"></li>
<li id="resourceFiles"></li>
<ul id="mimeStats"></ul>
</ul>
</div>
<div id="uploadResource" hidden="">
<p id="uploadResourceMessage">Ressurss on üleslaadimiseks valmis.</p>
<button id="uploadResourceButton">Panusta!</button>
</div>
<div id="uploading" hidden=""> <span>Kataloogid: </span><span id="uploadedResources">0</span><span>/</span><span id="uploadTotalResources">0</span>
<div id="resourceProgressbarOuter">
<div id="resourceProgressbarInner">
<div id="fileProgressbarInner"></div>
</div>
</div><span>Failid: </span><span id="uploadedSize">0</span><span>/</span><span id="uploadTotalSize">0</span>
<pre id="status"></pre>
</div>
<div id="thankYou" hidden="">
<h3>Aitäh!</h3>
<div>
<span>Su ressurss on kohal: </span>
<a id="resource_entu_link">siin</a>
</div>
</div>
<script src="./main.js"></script>
</body>
</html>
......@@ -20,12 +20,11 @@ UPLOADER_VERSION = pjson.name + ' v.' + pjson.version + (pjson.version.indexOf('
var ipc = require('ipc')
var b2s = require(path.join(__dirname, 'bytesToSize.js'))
var uploader = require(path.join(__dirname, 'upload.js'))
var user_data = {}
var resource = {}
var resource_stats = {}
var dom_resource_name = document.getElementById('resourceNameInput')
var dom_resource_stats = document.getElementById('resourceStats')
var renderer_interval
var initialize = function initialize() {
......@@ -59,7 +58,7 @@ function selectLocal () {
if (_paths.length === 1) {
var single_file = _paths[0]
op.set(resource, 'name', path.basename(single_file))
dom_resource_name.value = resource.name
document.getElementById('resourceNameInput').value = resource.name
fs.stat(single_file, function(err, stats) {
if (err) {
throw (err)
......@@ -86,14 +85,20 @@ function selectLocal () {
}
var resourceLoaded = function resourceLoaded() {
renderResource()
setFormState('loaded')
clearInterval(renderer_interval)
if (document.getElementById('resourceNameInput').value === '') {
document.getElementById('resourceNameInput').focus()
}
// ipc.send('data', resource)
renderResource()
document.getElementById('uploadResourceButton').onclick = function uploadResource() {
uploader.upload()
}
}
var renderResource = function renderResource() {
dom_resource_stats.removeAttribute('hidden')
document.getElementById('resourceStats').removeAttribute('hidden')
document.getElementById('resourceDirectories').innerHTML = ''
document.getElementById('resourceFiles').innerHTML = ''
document.getElementById('mimeStats').innerHTML = ''
......@@ -158,7 +163,6 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) {
})
}
var uploadResource = require(path.join(__dirname, 'upload.js'))
var setFormState = function setFormState(state) {
switch(state) {
......
......@@ -4,6 +4,9 @@ var op = require('object-path')
var path = require('path')
var async = require('async')
var remote = require('remote')
var dialog = remote.require('dialog')
var b2s = require(path.join(__dirname, '..', 'code', 'bytesToSize.js'))
var resource_root_eid = 4387
......@@ -13,12 +16,13 @@ var uploaded_files_progress
ENTU_API_ENTITY = 'https://entu.keeleressursid.ee/api2/entity'
ENTU_API_FILE = 'https://entu.keeleressursid.ee/api2/file'
var main = function main() {
var upload = function upload() {
op.set(resource, ['name'], document.getElementById('resourceNameInput').value)
uploaded_resources_progress = 0
uploaded_files_progress = 0
setFormState('uploading')
// console.log(JSON.stringify(resource_stats, null, 4))
// console.log(JSON.stringify(resource, null, 4))
// setFormState('uploading')
console.log(JSON.stringify(resource, null, 4))
document.getElementById('uploadTotalResources').innerHTML = (resource_stats.directories.count + 1)
document.getElementById('uploadTotalSize').innerHTML = b2s(resource_stats.files.size)
renderer_interval = setInterval(function () {
......@@ -26,20 +30,22 @@ var main = function main() {
}, 250)
setFormState('uploading')
recurseResources(resource_root_eid, resource, resourcesCreated)
}
var resourcesCreated = function resourcesCreated(err) {
if (err) { throw(err) }
async.parallelLimit(file_upload_tasks, 3, function filesUploaded() {
setFormState('uploaded')
document.getElementById('resource_entu_link').setAttribute('href', 'https://entu.keeleressursid.ee/entity/resource/' + resource.eid)
document.getElementById('resource_entu_link').onclick = openResourceInBrowser
// ipc.send('data', resource)
clearInterval(renderer_interval)
renderProgress()
})
}
var recurseResources = function recurseResources(parent_eid, resource, resourcesCreatedCB) {
// console.log('Recurse under EID:', parent_eid)
console.log('Recurse under EID:', parent_eid)
createEntuResource(parent_eid, resource, function resourceCreatedCB(err, new_eid) {
if (err) { return resourcesCreatedCB(err) }
async.each(op.get(resource, ['resources'], []), function iterator(child_resource, callback) {
......@@ -52,6 +58,11 @@ var recurseResources = function recurseResources(parent_eid, resource, resources
}
var openResourceInBrowser = function openResourceInBrowser() {
require('shell').openExternal('https://entu.keeleressursid.ee/entity/resource/' + resource.eid)
return false
}
var renderProgress = function renderProgress() {
// dom_resource_stats.removeAttribute('hidden')
document.getElementById('resourceProgressbarInner').style.width = (uploaded_resources_progress * 100 / (resource_stats.directories.count + 1)) + '%'
......@@ -62,13 +73,13 @@ var renderProgress = function renderProgress() {
}
module.exports = main
var file_upload_tasks = []
var createEntuResource = function createEntuResource(parent_eid, resource, callback) {
console.log('create under EID:', parent_eid)
var xhr = new window.XMLHttpRequest()
xhr.open('POST', ENTU_API_ENTITY + '-' + parent_eid, true)
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
......@@ -76,8 +87,10 @@ var createEntuResource = function createEntuResource(parent_eid, resource, callb
xhr.setRequestHeader('X-Auth-Token', user_data['session_key'])
xhr.onload = function () {
var new_eid = op.get(JSON.parse(this.responseText), ['result', 'id'], false)
console.log('Looking for new EID:', new_eid)
if (new_eid) {
// console.log('onload new EID:', new_eid)
console.log('onload new EID:', new_eid)
op.set(resource, ['eid'], new_eid)
addEntuProperties(new_eid, {
"resource-name": path.basename(op.get(resource, ['name'], 'nameless resource')),
"resource-uploader-version": UPLOADER_VERSION
......@@ -101,6 +114,7 @@ var createEntuResource = function createEntuResource(parent_eid, resource, callb
}
}
xhr.onerror = function(err) {
console.log('error:', err)
callback(err)
}
xhr.send('definition=resource')
......@@ -159,3 +173,5 @@ var addEntuProperties = function addEntuProperties(eid, data, callback) {
}
xhr.send(data)
}
module.exports.upload = upload
......@@ -2,7 +2,7 @@
"name": "Panustaja",
"description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.",
"version": "1.0.1-d",
"build": 94,
"build": 95,
"main": "./code/app.js",
"license": "CC-SA",
"private": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment