diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index 6c4d208..5d0513a 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -2,6 +2,13 @@ // Angular file upload hack // // TODO modularize for reuse +function analyzeFile(file, vm) { + vm.isZip = /\.zip$/.test(file.name); + vm.unzip = vm.isZip; + vm.stripZip = vm.isZip; + return vm; +} + function handleFiles(ev) { var selector = 'js-file-upload'; var $scope; @@ -15,10 +22,8 @@ function handleFiles(ev) { // 'vm' is the Controller As name. vm = $scope.vm; vm.currentFiles = ev.target.files; - var file = vm.currentFiles[0]; - vm.isZip = /\.zip$/.test(file.name); - vm.unzip = vm.isZip; - vm.stripZip = vm.isZip; + analyzeFile(vm.currentFiles[0], vm); + $scope.$digest(); console.log('[handleFiles] vm.currentFiles:'); console.log(vm.currentFiles); @@ -46,7 +51,7 @@ app.controller('websiteCtrl', [ var vm = this; vm.domains = []; //vm.unzipPath = '/'; - vm.webPath = '/'; + vm.uploadPath = '/'; Auth.api = function (apiname, opts) { var els = []; @@ -154,26 +159,38 @@ app.controller('websiteCtrl', [ vm.currentHost = record.host; // .replace(new RegExp('\\.' + vm.domain.domain.replace(/\./g, '\\.') + '$', '')); }; + vm._uploadFileVm = function (pkg, opts) { + return vm._uploadFile(pkg, { + domain: vm.currentHost + , tld: vm.domain.tld + , sld: vm.domain.sld + , sub: vm.domain.sub + , newFile: vm.currentFiles[0] + , uploadPath: vm.uploadPath + , progress: vm + }); + }; vm._uploadFile = function (pkg, opts) { + opts.progress = opts.progress || opts; return pkg.add({ - hostname: opts.currentHost - , domain: opts.currentHost - , tld: opts.domain.tld - , sld: opts.domain.sld + hostname: opts.domain + , domain: opts.domain + , tld: opts.tld + , sld: opts.sld //, sub: opts.record.sub - , multipart: { site: opts.currentFiles[0] } + , multipart: { site: opts.newFile } , progress: function (ev) { // TODO must digest - opts.uploadPercent = Math.round((ev.loaded / ev.total) * 100); + opts.progress.uploadPercent = Math.round((ev.loaded / ev.total) * 100); // TODO GiB, MiB, KiB, etc - opts.uploadTotal = (ev.total / (1024 * 1024)).toFixed(2); - opts.uploadProgress = (ev.loaded / (1024 * 1024)).toFixed(2); + opts.progress.uploadTotal = (ev.total / (1024 * 1024)).toFixed(2); + opts.progress.uploadProgress = (ev.loaded / (1024 * 1024)).toFixed(2); } , unzip: opts.unzip , strip: opts.stripZip - , path: opts.webPath + , path: opts.uploadPath }).then(function (result) { - opts.uploadTotal = 0; + opts.progress.uploadTotal = 0; window.alert(JSON.stringify(result)); }); }; @@ -225,7 +242,7 @@ app.controller('websiteCtrl', [ if (vm.sites.some(function (r) { return -1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain)); })) { - vm._uploadFile(pkg, vm); + vm._uploadFileVm(pkg, vm); return; } @@ -270,7 +287,7 @@ app.controller('websiteCtrl', [ return prom.then(function () { return pkg.claim(domainReq).then(function (result) { - return vm._uploadFile(pkg, vm); + return vm._uploadFileVm(pkg, vm); }); }); @@ -278,10 +295,12 @@ app.controller('websiteCtrl', [ }; vm.Sites.setUpload = function (r) { console.log("Hey! At least it can tell if there's a change!"); + analyzeFile(r.newFile, r); console.log(r); }; vm.Sites.upload = function (r) { var pkg = Auth.oauth3.pkg('www@daplie.com'); + //analyzeFile(r.newFile, r); vm._uploadFile(pkg, r); }; vm.Sites.archive = function (r) { @@ -293,7 +312,7 @@ app.controller('websiteCtrl', [ , tld: r.tld , sld: r.sld //, sub: vm.record.sub - //, path: vm.webPath + //, path: vm.uploadPath }).then(function (result) { window.alert(JSON.stringify(result)); // TODO use iframe to initiate download? @@ -312,7 +331,7 @@ app.controller('websiteCtrl', [ , tld: r.tld , sld: r.sld //, sub: vm.record.sub - //, path: vm.webPath + //, path: vm.uploadPath }).then(function (result) { window.alert(JSON.stringify(result)); }); diff --git a/templates/website.html b/templates/website.html index 4a5a5a1..20d0b97 100644 --- a/templates/website.html +++ b/templates/website.html @@ -62,7 +62,7 @@
99% | 1 MiB / 100 MiB
-
+
@@ -119,7 +119,7 @@
99% | 1 MiB / 100 MiB
-
+