Commit f46361fd authored by Mihkel Putrinš's avatar Mihkel Putrinš

style

parent f89c9011
var bytesToSize = function bytesToSize(bytes) {
function bytesToSize(bytes) {
if (bytes === undefined) bytes = 0
var sizes = ['B', 'KB', 'MB', 'GB', 'TB']
if (bytes === 0) return '0 B'
......
......@@ -21,7 +21,7 @@ var uploader = require(path.join(__dirname, 'upload.js'))
var user_data = {}
var data = ipc.sendSync('getUser', null)
var initialize = function initialize() {
function initialize() {
if (!data) {
data = JSON.parse(clipboard.readText())
clipboard.clear()
......@@ -47,6 +47,27 @@ var resource = {}
var resource_stats = {}
var renderer_interval
function renderResource() {
// console.log(JSON.stringify(op.get(resource_stats, 'mime'), null, 2))
document.getElementById('resourceStats').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)
})
}
function selectLocal () {
resource = {name: 'root'}
resource_stats = {files: {count: 0, size: 0}, directories: {count: 0}, mime:{}}
......@@ -87,7 +108,7 @@ function selectLocal () {
})
}
var resourceLoaded = function resourceLoaded() {
function resourceLoaded() {
renderResource()
setFormState('loaded')
clearInterval(renderer_interval)
......@@ -100,27 +121,7 @@ var resourceLoaded = function resourceLoaded() {
}
}
var renderResource = function renderResource() {
// console.log(JSON.stringify(op.get(resource_stats, 'mime'), null, 2))
document.getElementById('resourceStats').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) {
function recurseLocal(parent_resource, paths, loadedCB) {
async.each(paths, function iterator(_path, callback) {
fs.stat(_path, function(err, stats) {
if (err) {
......@@ -163,7 +164,7 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) {
}
var setFormState = function setFormState(state) {
function setFormState(state) {
switch(state) {
case 'select':
document.getElementById('selectLocal').removeAttribute('hidden')
......
......@@ -16,7 +16,7 @@ var uploaded_files_progress
ENTU_API_ENTITY = 'https://entu.keeleressursid.ee/api2/entity'
ENTU_API_FILE = 'https://entu.keeleressursid.ee/api2/file'
var upload = function upload() {
function upload() {
op.set(resource, ['name'], document.getElementById('resourceNameInput').value)
uploaded_resources_progress = 0
......@@ -31,7 +31,7 @@ var upload = function upload() {
recurseResources(resource_root_eid, resource, resourcesCreated)
}
var resourcesCreated = function resourcesCreated(err) {
function resourcesCreated(err) {
if (err) { throw(err) }
async.parallelLimit(file_upload_tasks, 3, function filesUploaded() {
setFormState('uploaded')
......@@ -44,7 +44,7 @@ var resourcesCreated = function resourcesCreated(err) {
})
}
var recurseResources = function recurseResources(parent_eid, resource, resourcesCreatedCB) {
function recurseResources(parent_eid, resource, resourcesCreatedCB) {
console.log('Recurse under EID:', parent_eid)
createEntuResource(parent_eid, resource, function resourceCreatedCB(err, new_eid) {
if (err) { return resourcesCreatedCB(err) }
......@@ -58,12 +58,12 @@ var recurseResources = function recurseResources(parent_eid, resource, resources
}
var openResourceInBrowser = function openResourceInBrowser() {
function openResourceInBrowser() {
require('shell').openExternal('https://entu.keeleressursid.ee/entity/resource/' + resource.eid)
return false
}
var renderProgress = function renderProgress() {
function renderProgress() {
// dom_resource_stats.removeAttribute('hidden')
document.getElementById('resourceProgressbarInner').style.width = (uploaded_resources_progress * 100 / (resource_stats.directories.count + 1)) + '%'
document.getElementById('uploadedResources').innerHTML = uploaded_resources_progress
......@@ -78,7 +78,7 @@ var renderProgress = function renderProgress() {
var file_upload_tasks = []
var createEntuResource = function createEntuResource(parent_eid, resource, callback) {
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)
......@@ -125,7 +125,7 @@ var createEntuResource = function createEntuResource(parent_eid, resource, callb
}
var addEntuFile = function addEntuFile(eid, file_path, callback) {
function addEntuFile(eid, file_path, callback) {
var options = {
url: ENTU_API_FILE,
......@@ -161,7 +161,7 @@ var addEntuFile = function addEntuFile(eid, file_path, callback) {
})
}
var addEntuProperties = function addEntuProperties(eid, data, callback) {
function addEntuProperties(eid, data, callback) {
var url_data = Object.keys(data).map(function (ix) {return ix + '=' + data[ix]}).join('&')
// console.log(url_data)
var xhr = new window.XMLHttpRequest()
......
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