2017-09-29 00:04:04 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var app = window.app;
|
2017-08-18 19:41:38 +00:00
|
|
|
//
|
|
|
|
// Angular file upload hack
|
|
|
|
//
|
|
|
|
// TODO modularize for reuse
|
2017-09-01 23:35:04 +00:00
|
|
|
function analyzeFile(file, vm) {
|
2017-10-05 23:34:27 +00:00
|
|
|
vm.triggerFileRefresh = 'changed';
|
2017-09-01 23:35:04 +00:00
|
|
|
vm.isZip = /\.zip$/.test(file.name);
|
|
|
|
vm.unzip = vm.isZip;
|
|
|
|
vm.stripZip = vm.isZip;
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
2017-09-29 00:04:04 +00:00
|
|
|
/*
|
2017-08-18 19:41:38 +00:00
|
|
|
function handleFiles(ev) {
|
|
|
|
var selector = 'js-file-upload';
|
|
|
|
var $scope;
|
|
|
|
var vm;
|
|
|
|
|
|
|
|
if ('INPUT' !== ev.target.tagName || 'file' !== ev.target.type || -1 === ev.target.className.indexOf(selector)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-23 20:36:19 +00:00
|
|
|
$scope = angular.element(ev.target).scope();
|
2017-08-18 19:41:38 +00:00
|
|
|
// 'vm' is the Controller As name.
|
|
|
|
vm = $scope.vm;
|
|
|
|
vm.currentFiles = ev.target.files;
|
2017-09-01 23:35:04 +00:00
|
|
|
analyzeFile(vm.currentFiles[0], vm);
|
|
|
|
|
2017-08-23 20:36:19 +00:00
|
|
|
$scope.$digest();
|
2017-08-25 01:40:22 +00:00
|
|
|
console.log('[handleFiles] vm.currentFiles:');
|
|
|
|
console.log(vm.currentFiles);
|
2017-08-18 19:41:38 +00:00
|
|
|
}
|
|
|
|
window.document.body.addEventListener('change', handleFiles);
|
2017-09-29 00:04:04 +00:00
|
|
|
*/
|
2017-09-01 22:39:21 +00:00
|
|
|
|
2017-09-25 23:15:52 +00:00
|
|
|
app.directive('daplieFileChange', [function () {
|
2017-09-01 22:39:21 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require:"ngModel",
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
element.bind('change', function (event) {
|
|
|
|
var files = event.target.files;
|
|
|
|
ngModel.$setViewValue(files[0]);
|
|
|
|
scope.$eval(attrs.daplieFileChange);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2017-09-25 23:15:52 +00:00
|
|
|
}]);
|
|
|
|
|
|
|
|
app.directive('fileTree', [function () {
|
|
|
|
return {
|
|
|
|
restrict: 'EA',
|
|
|
|
templateUrl: '/templates/widgets/filetree.html',
|
|
|
|
};
|
|
|
|
}]);
|
2017-09-01 22:39:21 +00:00
|
|
|
|
2017-10-05 19:01:05 +00:00
|
|
|
app.directive('notificationBar', [function () {
|
|
|
|
return {
|
|
|
|
restrict: 'EA',
|
|
|
|
templateUrl: '/templates/widgets/website-notification-bar.html',
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
|
2017-08-15 15:37:37 +00:00
|
|
|
app.controller('websiteCtrl', [
|
2017-11-01 18:10:39 +00:00
|
|
|
'$scope', '$q', 'Auth', 'azp@oauth3.org', '$timeout', '$sce', '$rootScope', '$location',
|
|
|
|
function ($scope, $q, Auth, Oauth3, $timeout, $sce, $rootScope, $location) {
|
2017-08-08 06:35:11 +00:00
|
|
|
|
2017-08-15 16:56:46 +00:00
|
|
|
var vm = this;
|
2017-09-29 00:04:04 +00:00
|
|
|
var angular = window.angular;
|
2017-08-16 22:35:04 +00:00
|
|
|
vm.domains = [];
|
2017-10-05 23:34:27 +00:00
|
|
|
vm.copyUploadPath = '';
|
2017-10-05 19:01:05 +00:00
|
|
|
vm.displaySpinner = '';
|
2017-10-05 23:34:27 +00:00
|
|
|
vm.deleteAll = '';
|
2017-11-03 22:44:09 +00:00
|
|
|
vm.referrerSelectedDomain = false;
|
2017-10-05 19:01:05 +00:00
|
|
|
vm.alertNotification = {
|
|
|
|
hidden: 'hidden'
|
|
|
|
};
|
2017-08-23 20:36:19 +00:00
|
|
|
//vm.unzipPath = '/';
|
2017-09-01 23:35:04 +00:00
|
|
|
vm.uploadPath = '/';
|
2017-08-16 22:35:04 +00:00
|
|
|
|
2017-09-29 00:04:04 +00:00
|
|
|
// already validated
|
|
|
|
function domainIsVerified(r) {
|
|
|
|
return r.verifiedAt || r.mode;
|
|
|
|
}
|
|
|
|
|
2017-08-18 19:41:38 +00:00
|
|
|
Auth.api = function (apiname, opts) {
|
|
|
|
var els = [];
|
|
|
|
|
|
|
|
return $q.all(Auth.sessions.map(function (session) {
|
|
|
|
|
2017-08-23 18:54:50 +00:00
|
|
|
return Auth.get(session).then(function (oauth3) {
|
2017-08-18 19:41:38 +00:00
|
|
|
|
|
|
|
return oauth3.api(apiname, {}).then(function (collection) {
|
|
|
|
|
|
|
|
if (collection.error) {
|
|
|
|
// not all tokens support all apis
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Array.isArray(collection)) {
|
|
|
|
console.error('collection is not an array');
|
|
|
|
console.error(collection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
collection.forEach(function (el) {
|
|
|
|
els.push(el);
|
|
|
|
el.session = session.token.sub + '@' + session.token.iss;
|
|
|
|
});
|
2017-08-16 22:35:04 +00:00
|
|
|
|
2017-10-31 18:51:42 +00:00
|
|
|
}, function(err) {
|
|
|
|
console.error("There was an error 1A", err);
|
|
|
|
return els;
|
|
|
|
});
|
2017-08-16 22:35:04 +00:00
|
|
|
});
|
2017-08-18 19:41:38 +00:00
|
|
|
})).then(function (results) {
|
|
|
|
return els;
|
2017-10-31 18:51:42 +00:00
|
|
|
}, function(err) {console.error("There was an error 1B", err)});
|
2017-08-18 19:41:38 +00:00
|
|
|
};
|
|
|
|
|
2017-08-14 19:45:19 +00:00
|
|
|
vm.getDomains = function () {
|
2017-08-18 20:12:22 +00:00
|
|
|
return Auth.oauth3.api('domains.list', {}).then(function (result) {
|
2017-08-14 19:45:19 +00:00
|
|
|
vm.domains = result.registrations || result;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-16 22:35:04 +00:00
|
|
|
vm.setDomain = function () {
|
|
|
|
if (!vm.domains || !vm.domains.length) {
|
|
|
|
vm.domain = { domain: vm.newDomain };
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.domains.some(function (domain) {
|
|
|
|
if (domain.domain === vm.newDomain) {
|
|
|
|
vm.domain = domain;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!vm.domain) {
|
|
|
|
vm.domain = { domain: vm.newDomain };
|
|
|
|
}
|
2017-08-23 22:12:57 +00:00
|
|
|
|
|
|
|
if (!vm.domain.tld) {
|
|
|
|
var parts = vm.domain.domain.split('.');
|
|
|
|
vm.domain.sld = parts.shift();
|
|
|
|
vm.domain.tld = parts.join('.');
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.setRecord();
|
2017-08-16 22:35:04 +00:00
|
|
|
};
|
|
|
|
|
2017-08-14 19:45:19 +00:00
|
|
|
vm.selectDomain = function (domain) {
|
2017-08-25 01:40:22 +00:00
|
|
|
vm.domain = domain; //vm.selectedDomain.description;
|
|
|
|
vm.newDomain = vm.domain.domain;
|
2017-08-18 19:41:38 +00:00
|
|
|
|
|
|
|
return Auth.api('dns.list', { }).then(function (records) {
|
2017-08-14 19:45:19 +00:00
|
|
|
records = records.filter(function (r) {
|
2017-08-25 01:40:22 +00:00
|
|
|
return /^A(AAA)?$/i.test(r.type) && ((r.sld + '.' + r.tld) === vm.domain.domain || r.zone === vm.domain.domain);
|
2017-08-14 19:45:19 +00:00
|
|
|
});
|
|
|
|
vm.records = records;
|
2017-08-18 19:41:38 +00:00
|
|
|
records.forEach(function (record) {
|
|
|
|
if (!record.sub) {
|
|
|
|
record.sub = record.host.replace('.' + record.zone, '');
|
|
|
|
if (record.host === record.zone) {
|
|
|
|
record.sub = '@';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-08-25 01:40:22 +00:00
|
|
|
console.log('[selectDomain] dns records:');
|
|
|
|
console.log(records);
|
2017-08-14 19:45:19 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-11-06 23:05:04 +00:00
|
|
|
vm.setRecordDomain = function(domain) {
|
|
|
|
vm.domain.sub = vm.newRecord || '';
|
|
|
|
if (vm.record !== undefined) {
|
|
|
|
domain.title = vm.record.host;
|
|
|
|
domain.description.domain = vm.record.host;
|
|
|
|
domain.originalObject.domain = vm.record.host;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-23 22:12:57 +00:00
|
|
|
vm.setRecord = function () {
|
|
|
|
// TODO set record based on (record.host === sub + domain.domain)
|
|
|
|
var sub = vm.newRecord;
|
|
|
|
|
2017-11-06 19:59:29 +00:00
|
|
|
if ('@' === sub || sub === undefined) {
|
2017-08-23 22:12:57 +00:00
|
|
|
sub = '';
|
|
|
|
}
|
|
|
|
vm.record = { sub: sub, host: (sub ? sub + '.' : '') + vm.domain.domain };
|
|
|
|
vm.currentHost = vm.record.host;
|
2017-08-25 01:40:22 +00:00
|
|
|
console.log('[setRecord] vm.record:');
|
|
|
|
console.log(vm.record);
|
2017-08-23 22:12:57 +00:00
|
|
|
};
|
|
|
|
|
2017-11-03 22:44:09 +00:00
|
|
|
vm.paramInit = function () {
|
|
|
|
// Share example -> ?token=fe8386d7ad6273bd9ca29864148c0d2d
|
2017-10-31 21:55:05 +00:00
|
|
|
if ($rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].params.token !== undefined) {
|
|
|
|
vm.Shares.inviteToken = $rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].params.token;
|
2017-10-30 21:45:58 +00:00
|
|
|
var result = { data: { info: true } };
|
2017-10-31 18:24:52 +00:00
|
|
|
var msg = "You have a new share.";
|
2017-10-30 21:45:58 +00:00
|
|
|
vm.buildNotification(result, msg);
|
|
|
|
}
|
2017-11-03 22:44:09 +00:00
|
|
|
console.log($rootScope,$location);
|
|
|
|
// Referrer example -> #referrer=daplieeleven.daplie.me
|
|
|
|
vm.referrerSelectedDomainName = $location.url().split('=')[1];
|
|
|
|
if ($location.url().includes('referrer')) {
|
|
|
|
$timeout(function() {
|
|
|
|
var el = document.querySelector('.create-share-btn');
|
|
|
|
el.click();
|
|
|
|
vm.referrerSelectedDomain = true;
|
|
|
|
}, 0);
|
|
|
|
}
|
2017-10-30 21:45:58 +00:00
|
|
|
};
|
|
|
|
|
2017-08-14 19:45:19 +00:00
|
|
|
vm.selectRecord = function (record) {
|
|
|
|
vm.record = record;
|
2017-08-18 19:41:38 +00:00
|
|
|
vm.newRecord = record.sub;
|
2017-08-14 19:45:19 +00:00
|
|
|
vm.currentHost = record.host; // .replace(new RegExp('\\.' + vm.domain.domain.replace(/\./g, '\\.') + '$', ''));
|
|
|
|
};
|
|
|
|
|
2017-09-01 23:35:04 +00:00
|
|
|
vm._uploadFileVm = function (pkg, opts) {
|
|
|
|
return vm._uploadFile(pkg, {
|
2017-09-29 00:04:04 +00:00
|
|
|
domain: opts.currentHost
|
|
|
|
, tld: opts.domain.tld
|
|
|
|
, sld: opts.domain.sld
|
|
|
|
, sub: opts.domain.sub
|
|
|
|
, newFile: opts.newFile
|
|
|
|
, uploadPath: opts.uploadPath
|
|
|
|
, progress: opts
|
2017-09-01 23:35:04 +00:00
|
|
|
});
|
|
|
|
};
|
2017-09-01 22:39:21 +00:00
|
|
|
vm._uploadFile = function (pkg, opts) {
|
2017-10-05 19:01:05 +00:00
|
|
|
vm.newFileUploaded = opts.newFile.name;
|
2017-09-01 23:35:04 +00:00
|
|
|
opts.progress = opts.progress || opts;
|
2017-08-22 18:37:57 +00:00
|
|
|
return pkg.add({
|
2017-09-01 23:35:04 +00:00
|
|
|
hostname: opts.domain
|
|
|
|
, domain: opts.domain
|
|
|
|
, tld: opts.tld
|
|
|
|
, sld: opts.sld
|
2017-11-07 21:45:11 +00:00
|
|
|
, sub: opts.sub
|
2017-09-01 23:35:04 +00:00
|
|
|
, multipart: { site: opts.newFile }
|
2017-08-25 23:48:14 +00:00
|
|
|
, progress: function (ev) {
|
|
|
|
// TODO must digest
|
2017-09-01 23:35:04 +00:00
|
|
|
opts.progress.uploadPercent = Math.round((ev.loaded / ev.total) * 100);
|
2017-08-25 23:48:14 +00:00
|
|
|
// TODO GiB, MiB, KiB, etc
|
2017-09-01 23:35:04 +00:00
|
|
|
opts.progress.uploadTotal = (ev.total / (1024 * 1024)).toFixed(2);
|
|
|
|
opts.progress.uploadProgress = (ev.loaded / (1024 * 1024)).toFixed(2);
|
2017-08-25 23:48:14 +00:00
|
|
|
}
|
2017-09-01 22:39:21 +00:00
|
|
|
, unzip: opts.unzip
|
|
|
|
, strip: opts.stripZip
|
2017-09-01 23:35:04 +00:00
|
|
|
, path: opts.uploadPath
|
2017-08-22 18:37:57 +00:00
|
|
|
}).then(function (result) {
|
2017-10-20 21:02:03 +00:00
|
|
|
if (result.data.error) {
|
|
|
|
var msg = vm.newFileUploaded + " has encountered an error. " + result.data.error.message + '.';
|
|
|
|
} else {
|
2017-10-26 17:08:34 +00:00
|
|
|
var msg = "'" + vm.newFileUploaded + "'" + " has been uploaded.";
|
|
|
|
vm.uploadFolderContainer = false;
|
|
|
|
vm.uploadFileContainer = false;
|
2017-10-20 21:02:03 +00:00
|
|
|
}
|
2017-10-05 19:01:05 +00:00
|
|
|
vm.buildNotification(result, msg);
|
2017-11-06 20:30:25 +00:00
|
|
|
if (vm.copyR !== undefined) {
|
|
|
|
vm.cleanArrays();
|
|
|
|
var path = vm.breadcrumbsPath.join('/');
|
|
|
|
cleanPathQuery(path);
|
|
|
|
vm.Sites.contents(vm.copyR, vm.cleanedPath);
|
2017-11-06 23:05:04 +00:00
|
|
|
} else {
|
|
|
|
$location.url($location.path());
|
2017-11-06 20:30:25 +00:00
|
|
|
}
|
2017-08-22 18:37:57 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
vm._isSubDomain = function (sub, domain) {
|
2017-08-23 18:42:18 +00:00
|
|
|
return -1 !== ('.' + sub).indexOf(('.' + domain));
|
2017-08-22 18:37:57 +00:00
|
|
|
};
|
|
|
|
|
2017-08-24 17:26:29 +00:00
|
|
|
vm.Sites = {};
|
|
|
|
vm.Sites.create = function () {
|
2017-08-18 20:12:22 +00:00
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
2017-08-22 18:37:57 +00:00
|
|
|
var parts;
|
|
|
|
var sub;
|
|
|
|
var sld;
|
|
|
|
var tld;
|
2017-09-29 00:04:04 +00:00
|
|
|
/*
|
2017-08-18 19:41:38 +00:00
|
|
|
//vm.unlock('webpreneur');
|
|
|
|
if (!vm.currentFiles || !vm.currentFiles.length) {
|
|
|
|
window.alert('No files chosen.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (1 !== vm.currentFiles.length) {
|
|
|
|
window.alert('Too many files chosen.');
|
|
|
|
return;
|
|
|
|
}
|
2017-09-29 00:04:04 +00:00
|
|
|
*/
|
2017-11-07 21:45:11 +00:00
|
|
|
debugger;
|
2017-09-29 00:04:04 +00:00
|
|
|
if (!vm.newFile) {
|
|
|
|
window.alert('No file chosen.');
|
|
|
|
return;
|
|
|
|
}
|
2017-08-18 19:41:38 +00:00
|
|
|
if (!vm.currentHost) {
|
2017-11-06 19:59:29 +00:00
|
|
|
vm.setRecord();
|
2017-08-18 19:41:38 +00:00
|
|
|
}
|
2017-08-14 19:45:19 +00:00
|
|
|
|
2017-08-22 18:37:57 +00:00
|
|
|
if (vm.domain) {
|
2017-08-23 22:12:57 +00:00
|
|
|
if (!vm.domain.tld || !vm.domain.sld) {
|
|
|
|
parts = vm.domain.domain.split('.');
|
|
|
|
sld = parts.shift();
|
|
|
|
tld = parts.join('.');
|
|
|
|
} else {
|
|
|
|
sld = vm.domain.sld;
|
|
|
|
tld = vm.domain.tld;
|
2017-11-06 23:05:04 +00:00
|
|
|
sub = vm.domain.sub;
|
2017-08-23 22:12:57 +00:00
|
|
|
}
|
2017-08-22 18:37:57 +00:00
|
|
|
} else {
|
|
|
|
parts = vm.currentHost.split('.');
|
|
|
|
// TODO get list of tlds
|
|
|
|
tld = parts.pop();
|
|
|
|
sld = parts.pop();
|
|
|
|
sub = parts.join('.');
|
|
|
|
}
|
2017-11-07 21:45:11 +00:00
|
|
|
|
2017-08-23 22:12:57 +00:00
|
|
|
if (vm.sites.some(function (r) {
|
2017-09-29 00:04:04 +00:00
|
|
|
return (-1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain))) && domainIsVerified(r);
|
2017-08-23 22:12:57 +00:00
|
|
|
})) {
|
2017-09-01 23:35:04 +00:00
|
|
|
vm._uploadFileVm(pkg, vm);
|
2017-08-23 22:12:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-22 18:37:57 +00:00
|
|
|
// We're making a request to claim a domain
|
|
|
|
// (because two users could both claim a single domain)
|
|
|
|
// We're claiming it at the top level (i.e. example.com)
|
|
|
|
// but we could also claim it at the subdomain level (needs UI update)
|
2017-11-06 23:05:04 +00:00
|
|
|
var domainReq = { sld: sld, tld: tld, sub: sub };
|
2017-11-07 21:45:11 +00:00
|
|
|
debugger;
|
2017-08-23 18:42:18 +00:00
|
|
|
return pkg.request(domainReq).then(function (result) {
|
2017-08-22 18:37:57 +00:00
|
|
|
var sess;
|
|
|
|
var prom;
|
|
|
|
var def;
|
2017-11-07 21:45:11 +00:00
|
|
|
var sub;
|
2017-08-22 18:37:57 +00:00
|
|
|
|
|
|
|
// can validate automatically
|
|
|
|
if (vm.domain.session && vm._isSubDomain(vm.currentHost, vm.domain.domain)) {
|
|
|
|
// this should always succeed
|
|
|
|
Auth.sessions.some(function (session) {
|
|
|
|
if (vm.domain.session === (session.token.sub + '@' + session.token.iss)) {
|
|
|
|
sess = session;
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (sess) {
|
2017-08-23 18:54:50 +00:00
|
|
|
prom = Auth.get(sess).then(function (oauth3) {
|
2017-11-07 21:45:11 +00:00
|
|
|
sub = result.data.prefix;
|
|
|
|
if (result.data.sub) {
|
|
|
|
sub = result.data.sub + '.' + result.data.prefix;
|
|
|
|
}
|
|
|
|
return oauth3.api('dns.set', { sld: sld, tld: tld, sub: sub, type: 'TXT', ttl: 5, value: result.data.challenge });
|
2017-08-22 18:37:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prom) {
|
|
|
|
def = $q.defer();
|
|
|
|
// must validate manually
|
|
|
|
window.alert(
|
|
|
|
"Please set a TXT record for '"
|
|
|
|
+ ('' + result.data.prefix) + '.' + sld + '.' + tld
|
|
|
|
+ "' with the value '" + result.data.challenge + "' and then continue."
|
|
|
|
);
|
|
|
|
def.resolve();
|
|
|
|
prom = def.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prom.then(function () {
|
2017-08-23 18:42:18 +00:00
|
|
|
return pkg.claim(domainReq).then(function (result) {
|
2017-09-01 23:35:04 +00:00
|
|
|
return vm._uploadFileVm(pkg, vm);
|
2017-08-23 18:42:18 +00:00
|
|
|
});
|
2017-08-22 18:37:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
2017-10-17 16:22:21 +00:00
|
|
|
|
2017-09-01 22:39:21 +00:00
|
|
|
vm.Sites.setUpload = function (r) {
|
|
|
|
console.log("Hey! At least it can tell if there's a change!");
|
2017-10-20 21:02:03 +00:00
|
|
|
if (r.newFile === undefined) {
|
|
|
|
r.newFile = vm.newFile;
|
|
|
|
}
|
2017-09-01 23:35:04 +00:00
|
|
|
analyzeFile(r.newFile, r);
|
2017-09-01 22:39:21 +00:00
|
|
|
console.log(r);
|
|
|
|
};
|
2017-10-17 16:22:21 +00:00
|
|
|
|
2017-10-26 17:08:34 +00:00
|
|
|
vm.cleanUploads = function (r) {
|
|
|
|
vm.folderName = '';
|
|
|
|
};
|
2017-10-17 16:22:21 +00:00
|
|
|
|
2017-10-17 19:51:08 +00:00
|
|
|
vm.Sites.allContents = function (r) {
|
|
|
|
vm.copyR = r;
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.contents({
|
2017-10-27 19:56:43 +00:00
|
|
|
hostname: r.domain
|
|
|
|
, domain: r.domain
|
|
|
|
, tld: r.tld
|
|
|
|
, sld: r.sld
|
2017-11-07 22:04:02 +00:00
|
|
|
, sub: r.sub
|
2017-10-27 19:56:43 +00:00
|
|
|
, path: r.shareAccess.path
|
2017-10-17 19:51:08 +00:00
|
|
|
}).then(function (result) {
|
2017-10-27 23:11:28 +00:00
|
|
|
vm.cleanArrays();
|
2017-10-17 19:51:08 +00:00
|
|
|
vm.folderStructure = result;
|
|
|
|
result.data.forEach(function(data){
|
|
|
|
if (data.file) {
|
|
|
|
vm.siteFiles.push(data.name);
|
|
|
|
}
|
|
|
|
if (data.directory) {
|
|
|
|
vm.siteDirectories.push(data.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
vm.displaySpinner = 'hidden';
|
2017-10-25 19:46:05 +00:00
|
|
|
vm.currentFolder = vm.breadcrumbs[vm.breadcrumbs.length - 1];
|
2017-10-17 19:51:08 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-27 19:56:43 +00:00
|
|
|
var cleanPathQuery = function (path) {
|
2017-10-21 07:24:24 +00:00
|
|
|
vm.cleanedPath = path.replace(/\/+/g, '/');
|
|
|
|
return vm.cleanedPath;
|
|
|
|
};
|
|
|
|
|
2017-10-25 20:39:49 +00:00
|
|
|
vm.closeFileUploadsContainers = function () {
|
|
|
|
vm.uploadFolderContainer = false;
|
|
|
|
vm.uploadFileContainer = false;
|
|
|
|
};
|
|
|
|
|
2017-11-06 23:33:49 +00:00
|
|
|
vm.Sites.fileContents = function (file, r) {
|
2017-11-07 22:12:22 +00:00
|
|
|
var path = vm.breadcrumbsPath;
|
|
|
|
path.push(file);
|
|
|
|
path = path.join('/');
|
2017-11-07 22:04:02 +00:00
|
|
|
cleanPathQuery(path);
|
2017-11-06 23:33:49 +00:00
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.contentRange({
|
|
|
|
hostname: r.domain,
|
|
|
|
domain: r.domain,
|
|
|
|
tld: r.tld,
|
|
|
|
sld: r.sld,
|
2017-11-07 22:04:02 +00:00
|
|
|
sub: r.sub,
|
2017-11-06 23:33:49 +00:00
|
|
|
path: vm.cleanedPath
|
|
|
|
}).then(function (result) {
|
|
|
|
debugger;
|
|
|
|
vm.folderStructure = result;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-17 19:51:08 +00:00
|
|
|
vm.Sites.contents = function (r, dir) {
|
2017-10-21 07:24:24 +00:00
|
|
|
vm.siteFiles = [];
|
|
|
|
vm.siteDirectories = [];
|
2017-10-27 23:11:28 +00:00
|
|
|
dir = dir + '/';
|
2017-10-21 07:24:24 +00:00
|
|
|
cleanPathQuery(dir);
|
|
|
|
dir = vm.cleanedPath;
|
2017-10-25 22:25:29 +00:00
|
|
|
vm.previousSearchQuery = dir;
|
2017-10-17 19:51:08 +00:00
|
|
|
vm.displaySpinner = '';
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.contents({
|
2017-10-21 07:24:24 +00:00
|
|
|
hostname: r.domain,
|
|
|
|
domain: r.domain,
|
|
|
|
tld: r.tld,
|
|
|
|
sld: r.sld,
|
2017-11-07 22:04:02 +00:00
|
|
|
sub: r.sub,
|
2017-10-21 07:24:24 +00:00
|
|
|
path: dir
|
2017-10-17 19:51:08 +00:00
|
|
|
}).then(function (result) {
|
2017-10-27 21:01:13 +00:00
|
|
|
vm.cleanArrays();
|
2017-10-17 19:51:08 +00:00
|
|
|
vm.displaySpinner = 'hidden';
|
|
|
|
vm.folderStructure = result;
|
|
|
|
result.data.forEach(function(data){
|
|
|
|
if (data.file) {
|
|
|
|
vm.siteFiles.push(data.name);
|
|
|
|
}
|
|
|
|
if (data.directory) {
|
|
|
|
vm.siteDirectories.push(data.name);
|
|
|
|
}
|
|
|
|
});
|
2017-10-27 23:11:28 +00:00
|
|
|
vm.currentFolder = vm.breadcrumbs[vm.breadcrumbs.length - 1];
|
2017-10-17 19:51:08 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-21 07:24:24 +00:00
|
|
|
var crumbsCleanUp = function (crumb) {
|
|
|
|
var str2arryQuery = cleanPathQuery(vm.breadcrumbsPath.join('/'));
|
|
|
|
var str2arry = vm.breadcrumbs;
|
|
|
|
str2arryQuery = str2arryQuery.split('/');
|
2017-10-27 23:11:28 +00:00
|
|
|
if (vm.copyR.shareAccess.path !== '/') {
|
|
|
|
var removeFromBreadcrumbsQuery = str2arryQuery.indexOf(crumb) + 1;
|
|
|
|
var removeFromBreadcrumbs = str2arry.indexOf(crumb) + 1;
|
|
|
|
vm.breadcrumbsPath = str2arryQuery.splice(0,removeFromBreadcrumbsQuery);
|
|
|
|
vm.breadcrumbs = str2arry.splice(0,removeFromBreadcrumbs);
|
|
|
|
var strictPath = vm.strictPath.slice(0, -1);
|
|
|
|
if (vm.breadcrumbsPath.join('/').indexOf(strictPath) !== 0) {
|
|
|
|
vm.breadcrumbsPath = strictPath.split('/');
|
|
|
|
vm.breadcrumbs = strictPath.split('/');
|
|
|
|
vm.breadcrumbs.shift();
|
|
|
|
var result = { data: { warning: true } };
|
|
|
|
vm.currentFolder = vm.breadcrumbs[vm.breadcrumbs.length - 2];
|
2017-10-27 23:13:42 +00:00
|
|
|
var msg = "You can only view inside the " + "'" + vm.currentFolder + "'" + ' folder.';
|
2017-10-27 23:11:28 +00:00
|
|
|
vm.buildNotification(result, msg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var removeFromBreadcrumbsQuery = str2arryQuery.indexOf(crumb) + 1;
|
|
|
|
var removeFromBreadcrumbs = str2arry.indexOf(crumb) + 1;
|
|
|
|
vm.breadcrumbsPath = str2arryQuery.splice(0,removeFromBreadcrumbsQuery);
|
|
|
|
vm.breadcrumbs = str2arry.splice(0,removeFromBreadcrumbs);
|
|
|
|
}
|
2017-10-21 07:24:24 +00:00
|
|
|
};
|
|
|
|
|
2017-10-27 19:56:43 +00:00
|
|
|
var removeFolderCrumbsCleanUp = function (crumb) {
|
|
|
|
var str2arryQuery = cleanPathQuery(vm.breadcrumbsPath.join('/'));
|
|
|
|
var str2arry = vm.breadcrumbs;
|
|
|
|
str2arryQuery = str2arryQuery.split('/');
|
|
|
|
var removeFromBreadcrumbsQuery = str2arryQuery.indexOf(crumb);
|
|
|
|
var removeFromBreadcrumbs = str2arry.indexOf(crumb);
|
|
|
|
vm.breadcrumbsPath = str2arryQuery.splice(0,removeFromBreadcrumbsQuery);
|
|
|
|
vm.breadcrumbs = str2arry.splice(0,removeFromBreadcrumbs);
|
|
|
|
vm.copyR.fromFolder = vm.breadcrumbsPath.join('/');
|
2017-10-27 23:11:28 +00:00
|
|
|
vm.currentFolder = vm.breadcrumbs[vm.breadcrumbs.length - 1];
|
2017-10-27 19:56:43 +00:00
|
|
|
};
|
|
|
|
|
2017-10-17 19:51:08 +00:00
|
|
|
vm.getDirectoriesFromBreadcrumbs = function (dir) {
|
2017-10-27 19:56:43 +00:00
|
|
|
crumbsCleanUp(dir);
|
|
|
|
cleanPathQuery(vm.breadcrumbsPath.join('/'));
|
|
|
|
vm.Sites.contents(vm.copyR, vm.cleanedPath);
|
2017-10-25 19:46:05 +00:00
|
|
|
vm.currentFolder = vm.breadcrumbs[vm.breadcrumbs.length - 1];
|
2017-10-17 19:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
vm.getDirectories = function (dir) {
|
2017-10-27 19:56:43 +00:00
|
|
|
vm.breadcrumbs.push(dir);
|
|
|
|
vm.breadcrumbsPath.push(dir);
|
|
|
|
cleanPathQuery(vm.breadcrumbsPath.join('/'));
|
|
|
|
vm.Sites.contents(vm.copyR, vm.cleanedPath);
|
2017-10-25 19:46:05 +00:00
|
|
|
vm.currentFolder = vm.breadcrumbs[vm.breadcrumbs.length - 1];
|
2017-10-17 19:51:08 +00:00
|
|
|
};
|
|
|
|
|
2017-10-17 20:29:24 +00:00
|
|
|
vm.removeAllFiles = function (r, opts) {
|
|
|
|
opts = {
|
|
|
|
path: '/',
|
|
|
|
confirm: true
|
|
|
|
};
|
|
|
|
vm.Sites.remove(r, opts);
|
|
|
|
};
|
|
|
|
|
2017-10-27 19:56:43 +00:00
|
|
|
vm.deleteFilesFrom = function (r, file) {
|
2017-10-26 17:08:34 +00:00
|
|
|
vm.pathRemoved = file;
|
2017-10-27 19:56:43 +00:00
|
|
|
var path = vm.breadcrumbsPath.join('/');
|
|
|
|
path = path + '/' + file;
|
|
|
|
path = cleanPathQuery(path);
|
|
|
|
var opts = {
|
|
|
|
path: path
|
2017-10-17 20:29:24 +00:00
|
|
|
};
|
|
|
|
vm.Sites.remove(r, opts);
|
|
|
|
};
|
|
|
|
|
2017-10-27 19:56:43 +00:00
|
|
|
vm.deleteFromInsideOfFolder = false;
|
2017-10-25 19:46:05 +00:00
|
|
|
vm.triggerDeleteFolder = function (path, r) {
|
2017-10-27 19:56:43 +00:00
|
|
|
removeFolderCrumbsCleanUp(path);
|
|
|
|
vm.deleteFromInsideOfFolder = true;
|
|
|
|
path = vm.previousSearchQuery;
|
2017-10-25 19:46:05 +00:00
|
|
|
var opts = {
|
|
|
|
path: path
|
2017-10-26 17:08:34 +00:00
|
|
|
};
|
2017-10-27 19:56:43 +00:00
|
|
|
vm.cleanArrays();
|
2017-10-26 17:08:34 +00:00
|
|
|
vm.Sites.remove(r, opts);
|
|
|
|
};
|
2017-10-25 19:46:05 +00:00
|
|
|
|
2017-10-17 20:29:24 +00:00
|
|
|
vm.Sites.remove = function (r, opts) {
|
|
|
|
if (!window.confirm("Delete files for this site?")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
2017-11-02 23:00:39 +00:00
|
|
|
var removedPath = opts.path;
|
2017-10-17 20:29:24 +00:00
|
|
|
return pkg.remove({
|
2017-10-27 19:56:43 +00:00
|
|
|
hostname: r.domain
|
|
|
|
, domain: r.domain
|
|
|
|
, tld: r.tld
|
|
|
|
, sld: r.sld
|
2017-11-07 22:04:02 +00:00
|
|
|
, sub: r.sub
|
2017-10-27 19:56:43 +00:00
|
|
|
, path: opts.path || r.path
|
|
|
|
, confirm: opts.confirm || r.confirm
|
2017-10-17 20:29:24 +00:00
|
|
|
}).then(function (result) {
|
2017-10-27 19:56:43 +00:00
|
|
|
vm.cleanArrays();
|
|
|
|
if (vm.deleteFromInsideOfFolder) {
|
|
|
|
cleanPathQuery(vm.copyR.fromFolder);
|
|
|
|
vm.Sites.contents(vm.copyR, vm.cleanedPath);
|
2017-10-26 17:26:43 +00:00
|
|
|
} else {
|
2017-10-27 19:56:43 +00:00
|
|
|
cleanPathQuery(vm.breadcrumbsPath.join('/'));
|
2017-10-27 17:00:55 +00:00
|
|
|
vm.Sites.contents(vm.copyR, vm.cleanedPath);
|
2017-10-26 17:26:43 +00:00
|
|
|
}
|
2017-11-02 23:00:39 +00:00
|
|
|
var msg = 'Successfully deleted ' + "'" + removedPath + "'.";
|
|
|
|
vm.buildNotification(result, msg);
|
2017-10-17 20:29:24 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-24 17:26:29 +00:00
|
|
|
vm.Sites.archive = function (r) {
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
2017-11-02 23:00:39 +00:00
|
|
|
var path;
|
|
|
|
if (vm.breadcrumbsPath === undefined && vm.breadcrumbs === undefined) {
|
|
|
|
path = r.shareAccess.path;
|
|
|
|
} else {
|
|
|
|
cleanPathQuery(vm.breadcrumbsPath.join('/'));
|
|
|
|
path = vm.cleanedPath;
|
|
|
|
}
|
2017-11-03 19:14:06 +00:00
|
|
|
debugger;
|
2017-11-03 22:44:09 +00:00
|
|
|
// FIXME: Figure out how to download specific folders
|
2017-08-24 17:26:29 +00:00
|
|
|
return pkg.archive({
|
|
|
|
hostname: r.domain
|
|
|
|
, domain: r.domain
|
|
|
|
, tld: r.tld
|
|
|
|
, sld: r.sld
|
2017-11-03 19:14:06 +00:00
|
|
|
, sub: r.sub
|
|
|
|
, path: path
|
2017-08-24 17:26:29 +00:00
|
|
|
}).then(function (result) {
|
|
|
|
window.alert(JSON.stringify(result));
|
|
|
|
// TODO use iframe to initiate download?
|
|
|
|
window.open(result.data.url);
|
|
|
|
});
|
|
|
|
};
|
2017-10-02 18:29:53 +00:00
|
|
|
|
2017-10-17 21:19:41 +00:00
|
|
|
vm.shareFolderFrom = function (r, opts) {
|
|
|
|
var sharePath;
|
2017-11-02 16:14:58 +00:00
|
|
|
if (vm.breadcrumbsPath === undefined && vm.breadcrumbs === undefined) {
|
|
|
|
sharePath = '/';
|
|
|
|
} else if (vm.breadcrumbsPath.join('/') === '' && vm.breadcrumbs.join('/') === '') {
|
2017-10-17 21:19:41 +00:00
|
|
|
sharePath = '/';
|
2017-10-04 22:27:36 +00:00
|
|
|
} else {
|
2017-10-21 07:24:24 +00:00
|
|
|
sharePath = cleanPathQuery(vm.breadcrumbsPath.join('/'));
|
|
|
|
sharePath = sharePath + '/';
|
2017-10-04 22:27:36 +00:00
|
|
|
}
|
2017-10-27 23:11:28 +00:00
|
|
|
cleanPathQuery(sharePath);
|
2017-10-25 17:16:55 +00:00
|
|
|
opts = {
|
2017-10-27 23:11:28 +00:00
|
|
|
sharePath: vm.cleanedPath,
|
2017-10-25 17:16:55 +00:00
|
|
|
shareMode: vm.copiedShareMode
|
|
|
|
};
|
2017-10-17 21:19:41 +00:00
|
|
|
vm.Shares.invite(r, opts);
|
|
|
|
};
|
|
|
|
|
2017-10-17 22:52:57 +00:00
|
|
|
vm.createNewFolder = function (r) {
|
2017-10-27 19:56:43 +00:00
|
|
|
r.folderName = vm.folderName;
|
|
|
|
vm.breadcrumbsPath.push(r.folderName);
|
2017-10-17 22:52:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
vm.Sites.upload = function (r) {
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
2017-10-27 19:56:43 +00:00
|
|
|
cleanPathQuery(vm.breadcrumbsPath.join('/'))
|
|
|
|
r.uploadPath = vm.cleanedPath;
|
2017-10-17 22:52:57 +00:00
|
|
|
vm._uploadFile(pkg, r);
|
|
|
|
};
|
|
|
|
|
2017-10-17 21:19:41 +00:00
|
|
|
vm.Shares = {};
|
|
|
|
vm.Shares.invite = function (r, opts) {
|
2017-09-01 20:50:33 +00:00
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.invite({
|
2017-09-06 00:25:00 +00:00
|
|
|
comment: r.shareEmail
|
|
|
|
, email: r.shareEmail
|
2017-09-01 20:50:33 +00:00
|
|
|
, domain: r.domain
|
|
|
|
, tld: r.tld
|
|
|
|
, sld: r.sld
|
2017-11-07 22:04:02 +00:00
|
|
|
, sub: r.sub
|
2017-10-17 21:19:41 +00:00
|
|
|
, path: opts.sharePath || r.sharePath
|
|
|
|
, mode: opts.shareMode || r.shareMode
|
2017-09-01 20:50:33 +00:00
|
|
|
}).then(function (result) {
|
2017-09-06 20:12:37 +00:00
|
|
|
var arr = r.sharedWith || [];
|
|
|
|
arr.push(result.data);
|
|
|
|
r.sharedWith = arr;
|
2017-11-02 16:14:58 +00:00
|
|
|
var path = result.data.path;
|
|
|
|
var person = result.data.comment;
|
|
|
|
var msg = "You have shared " + "'" + path + "'" + ' with ' + person + ".";
|
|
|
|
vm.buildNotification(result, msg);
|
2017-09-01 20:50:33 +00:00
|
|
|
});
|
|
|
|
};
|
2017-10-17 16:22:21 +00:00
|
|
|
|
2017-09-01 20:50:33 +00:00
|
|
|
vm.Shares.accept = function () {
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.acceptInvite({
|
|
|
|
token: vm.Shares.inviteToken
|
|
|
|
}).then(function (result) {
|
2017-10-31 23:03:40 +00:00
|
|
|
if (result.data.error) {
|
|
|
|
var msg = result.data.error.message + '.';
|
|
|
|
vm.buildNotification(result, msg);
|
|
|
|
} else {
|
|
|
|
var person = result.data.comment;
|
|
|
|
var path = result.data.path;
|
|
|
|
var shareMode = result.data.mode;
|
|
|
|
var domain = result.data.domain;
|
|
|
|
var msg = 'You accepted a share ' + "'" + domain + "'" + ' from ' + person + '. Take a look at your verified websites below.';
|
|
|
|
vm.buildNotification(result, msg);
|
|
|
|
vm.listSites();
|
|
|
|
}
|
2017-11-01 18:10:39 +00:00
|
|
|
if ($location.$$search.token) {
|
|
|
|
delete $location.$$search.token;
|
|
|
|
vm.Shares.inviteToken = '';
|
|
|
|
$location.$$compose();
|
|
|
|
}
|
2017-09-01 20:50:33 +00:00
|
|
|
});
|
|
|
|
};
|
2017-10-17 16:22:21 +00:00
|
|
|
|
2017-09-06 00:25:00 +00:00
|
|
|
vm.Shares.list = function (r) {
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.listShares({
|
|
|
|
domain: r.domain
|
|
|
|
, hostname: r.domain
|
|
|
|
, tld: r.tld
|
|
|
|
, sld: r.sld
|
2017-11-07 22:04:02 +00:00
|
|
|
, sub: r.sub
|
2017-09-06 00:25:00 +00:00
|
|
|
, path: r.sharePath
|
|
|
|
}).then(function (result) {
|
2017-10-05 19:01:05 +00:00
|
|
|
vm.displaySpinner = 'hidden';
|
2017-09-06 00:25:00 +00:00
|
|
|
console.log('list shares result:');
|
|
|
|
console.log(result);
|
|
|
|
r.sharedWith = result.data;
|
|
|
|
//r.usersnames = r.sharedWith.map().join(',');
|
|
|
|
});
|
|
|
|
};
|
2017-10-17 16:22:21 +00:00
|
|
|
|
2017-10-18 20:58:03 +00:00
|
|
|
vm.deleteWebsite = function (r, s) {
|
|
|
|
if (!window.confirm("Delete this site?")) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-07 21:45:11 +00:00
|
|
|
s.sharePath = '/';
|
2017-10-18 20:58:03 +00:00
|
|
|
vm.Shares.remove(r, s);
|
2017-10-21 07:24:24 +00:00
|
|
|
};
|
2017-10-18 20:58:03 +00:00
|
|
|
|
2017-09-06 20:12:37 +00:00
|
|
|
vm.Shares.remove = function (r, s) {
|
|
|
|
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.removeShare({
|
|
|
|
domain: s.domain
|
|
|
|
, hostname: s.domain
|
|
|
|
, tld: s.tld
|
|
|
|
, sld: s.sld
|
2017-11-07 21:45:11 +00:00
|
|
|
, sub: r.sub
|
2017-09-06 20:12:37 +00:00
|
|
|
, path: s.sharePath
|
|
|
|
, challenge: s.challenge
|
|
|
|
}).then(function (result) {
|
2017-10-05 19:01:05 +00:00
|
|
|
var person = result.data.comment;
|
|
|
|
var msg = "revoked access from " + person;
|
|
|
|
vm.buildNotification(result, msg);
|
2017-09-06 20:12:37 +00:00
|
|
|
console.log('remove share result:');
|
|
|
|
console.log(result);
|
|
|
|
var index;
|
|
|
|
|
2017-11-07 21:45:11 +00:00
|
|
|
if (r.sharedWith !== undefined) {
|
|
|
|
r.sharedWith.forEach(function (_s, i) {
|
|
|
|
if (s.challenge === _s.challenge) {
|
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
});
|
2017-09-06 20:12:37 +00:00
|
|
|
|
2017-11-07 21:45:11 +00:00
|
|
|
r.sharedWith.splice(index, 1);
|
|
|
|
//r.usersnames = r.sharedWith.map().join(',');
|
|
|
|
}
|
2017-09-06 20:12:37 +00:00
|
|
|
});
|
|
|
|
};
|
2017-09-01 20:50:33 +00:00
|
|
|
|
2017-08-22 18:37:57 +00:00
|
|
|
vm.listSites = function () {
|
|
|
|
var sites = [];
|
|
|
|
return $q.all(Auth.sessions.map(function (session) {
|
2017-08-23 18:54:50 +00:00
|
|
|
return Auth.get(session).then(function (oauth3) {
|
2017-08-22 18:37:57 +00:00
|
|
|
var pkg = oauth3.pkg('www@daplie.com');
|
|
|
|
return pkg.list().then(function (result) {
|
2017-08-23 18:42:18 +00:00
|
|
|
var _sites = result.data;
|
|
|
|
if (Array.isArray(_sites)) {
|
|
|
|
sites = _sites.concat(sites);
|
2017-08-22 18:37:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-24 20:32:36 +00:00
|
|
|
console.error('_sites is not an array');
|
|
|
|
console.error(_sites);
|
2017-08-22 18:37:57 +00:00
|
|
|
}, function (err) {
|
2017-08-23 18:42:18 +00:00
|
|
|
console.error('_sites had an error');
|
2017-08-22 18:37:57 +00:00
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})).then(function () {
|
2017-09-29 00:04:04 +00:00
|
|
|
sites.forEach(function (site) {
|
|
|
|
site.pending = !domainIsVerified(site);
|
|
|
|
});
|
2017-10-24 20:32:36 +00:00
|
|
|
console.log('[listSites] sites:');
|
|
|
|
console.log(sites);
|
2017-08-22 18:37:57 +00:00
|
|
|
vm.sites = sites;
|
2017-09-28 21:10:50 +00:00
|
|
|
vm.sites.forEach(function(site) {
|
|
|
|
site.urlSafeDomain = "https://" + site.domain;
|
|
|
|
site.urlSafeDomain = $sce.trustAsResourceUrl(site.urlSafeDomain);
|
|
|
|
});
|
2017-08-18 20:12:22 +00:00
|
|
|
});
|
2017-08-14 19:45:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//vm.getDomains();
|
2017-08-22 18:37:57 +00:00
|
|
|
Auth.api('domains.list', {}).then(function (els) {
|
2017-10-02 17:10:20 +00:00
|
|
|
// console.log('[init] domains.list els:');
|
|
|
|
// console.log(els);
|
2017-11-03 22:44:09 +00:00
|
|
|
if (vm.referrerSelectedDomain) {
|
|
|
|
Object.keys(els).forEach(function (key) {
|
|
|
|
if (els[key]['domain'] === vm.referrerSelectedDomainName) {
|
2017-11-06 23:05:04 +00:00
|
|
|
$scope.domain = [];
|
|
|
|
$scope.domain.push(els[key]);
|
2017-11-03 22:44:09 +00:00
|
|
|
}
|
|
|
|
})
|
2017-11-06 23:05:04 +00:00
|
|
|
} else {
|
2017-11-03 22:44:09 +00:00
|
|
|
vm.domains = els;
|
|
|
|
$scope.domain = vm.domains;
|
|
|
|
}
|
2017-08-22 18:37:57 +00:00
|
|
|
});
|
2017-10-27 19:56:43 +00:00
|
|
|
|
2017-08-22 18:37:57 +00:00
|
|
|
vm.listSites();
|
2017-08-23 19:26:31 +00:00
|
|
|
|
2017-08-24 17:02:31 +00:00
|
|
|
vm.triggerDropdown = function() {
|
|
|
|
$timeout(function() {
|
|
|
|
var el = document.querySelector('.trigger-dropdown');
|
|
|
|
angular.element(el).triggerHandler('focus');
|
|
|
|
}, 0);
|
|
|
|
};
|
|
|
|
|
2017-10-17 23:59:18 +00:00
|
|
|
vm.cleanArrays = function () {
|
|
|
|
vm.breadcrumbsPath = [];
|
|
|
|
vm.breadcrumbs = [];
|
|
|
|
vm.siteFiles = [];
|
|
|
|
vm.siteDirectories = [];
|
2017-10-27 17:00:55 +00:00
|
|
|
if (vm.previousSearchQuery === undefined) {
|
2017-10-27 19:56:43 +00:00
|
|
|
vm.previousSearchQuery = '';
|
2017-10-27 17:00:55 +00:00
|
|
|
}
|
|
|
|
var getBreadcrumbsPath = vm.previousSearchQuery;
|
|
|
|
vm.breadcrumbsPath = getBreadcrumbsPath.split('/');
|
|
|
|
var getBreadcrumbs = vm.previousSearchQuery.split('/');
|
|
|
|
getBreadcrumbs.forEach(function(crumb){
|
|
|
|
if(crumb !== '') {
|
|
|
|
vm.breadcrumbs.push(crumb);
|
|
|
|
}
|
|
|
|
});
|
2017-11-06 19:59:29 +00:00
|
|
|
if (vm.copyR !== undefined) {
|
|
|
|
if (vm.copyR.shareAccess.path !== '/') {
|
|
|
|
} else {
|
|
|
|
vm.breadcrumbs.unshift('root');
|
|
|
|
}
|
2017-10-27 19:56:43 +00:00
|
|
|
}
|
2017-10-17 23:59:18 +00:00
|
|
|
};
|
2017-10-16 20:56:35 +00:00
|
|
|
|
|
|
|
vm.checkShareRights = function (r) {
|
|
|
|
if (r.invitedBy) {
|
|
|
|
r.shareAccess = { write: false, read: false, invite: false };
|
|
|
|
if (r.mode.includes('w')) {
|
|
|
|
r.shareAccess.write = true;
|
|
|
|
}
|
|
|
|
if (r.mode.includes('r')) {
|
|
|
|
r.shareAccess.read = true;
|
|
|
|
}
|
|
|
|
if (r.mode.includes('x')) {
|
|
|
|
r.shareAccess.invite = true;
|
|
|
|
}
|
|
|
|
r.shareAccess.path = r.path;
|
2017-10-27 17:00:55 +00:00
|
|
|
vm.strictPath = r.shareAccess.path;
|
|
|
|
vm.previousSearchQuery = vm.strictPath;
|
2017-10-16 20:56:35 +00:00
|
|
|
console.log(r.shareAccess);
|
|
|
|
} else {
|
|
|
|
r.shareAccess = { write: true, read: true, invite: true, path: '/' };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-25 01:40:22 +00:00
|
|
|
$scope.$watch('vm.selectedDomain', function (domainSelected) {
|
2017-08-24 17:02:31 +00:00
|
|
|
if (domainSelected !== undefined) {
|
2017-10-25 19:46:05 +00:00
|
|
|
vm.dom = domainSelected;
|
2017-11-06 23:05:04 +00:00
|
|
|
if (domainSelected.description === undefined) {
|
|
|
|
vm.selectDomain(domainSelected);
|
|
|
|
} else {
|
|
|
|
vm.selectDomain(vm.selectedDomain.description);
|
|
|
|
}
|
2017-08-24 17:02:31 +00:00
|
|
|
}
|
|
|
|
});
|
2017-08-23 19:26:31 +00:00
|
|
|
|
2017-10-21 07:24:24 +00:00
|
|
|
vm.getSharedAccess = function (access) {
|
|
|
|
vm.accessLevelArry = [];
|
|
|
|
vm.prettyAccessArray = [];
|
|
|
|
access.forEach(function(letter) {
|
|
|
|
vm.prettyAccessArray.push(letter.name);
|
|
|
|
vm.accessLevelArry.push(letter.value);
|
|
|
|
});
|
|
|
|
vm.prettyShareMode = vm.prettyAccessArray.join(", ");
|
|
|
|
vm.copiedShareMode = vm.accessLevelArry.join(",");
|
|
|
|
};
|
2017-10-04 22:27:36 +00:00
|
|
|
|
|
|
|
$scope.selectedAccess = [];
|
|
|
|
$scope.accessLevel = [{ name: 'Read', value: 'r' }, { name: 'Write', value: 'w' }, { name: 'Invite', value: 'x' }];
|
|
|
|
|
2017-08-23 19:26:31 +00:00
|
|
|
$scope.localDomainSearch = function(str, domain) {
|
|
|
|
var matches = [];
|
|
|
|
domain.forEach(function(domain) {
|
2017-08-23 23:07:15 +00:00
|
|
|
if ((domain.domain.toLowerCase().indexOf(str.toString().toLowerCase()) >= 0)) {
|
2017-08-23 19:26:31 +00:00
|
|
|
matches.push(domain);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return matches;
|
|
|
|
};
|
2017-09-07 21:26:22 +00:00
|
|
|
|
2017-09-28 21:10:50 +00:00
|
|
|
vm.showAction = function (action) {
|
|
|
|
switch(action) {
|
|
|
|
case 'invite':
|
|
|
|
vm.showInviteContainer = true;
|
|
|
|
vm.websiteTiles = true;
|
|
|
|
vm.showBackBtn = true;
|
2017-10-03 22:28:20 +00:00
|
|
|
vm.displayFileTree = true;
|
2017-10-05 23:39:18 +00:00
|
|
|
if (vm.currentFolder === undefined || vm.currentFolder === 'hidden' || vm.currentFolder === 'root') {
|
2017-10-05 23:34:27 +00:00
|
|
|
vm.currentFolder = 'All Folders/Files';
|
2017-10-04 03:17:36 +00:00
|
|
|
}
|
2017-09-28 21:10:50 +00:00
|
|
|
break;
|
|
|
|
case 'shares':
|
|
|
|
vm.showSharesContainer = true;
|
|
|
|
vm.websiteTiles = true;
|
|
|
|
vm.showBackBtn = true;
|
|
|
|
break;
|
|
|
|
case 'files':
|
|
|
|
vm.showFilesContainer = true;
|
|
|
|
vm.websiteTiles = true;
|
|
|
|
vm.showBackBtn = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-05 19:01:05 +00:00
|
|
|
vm.buildNotification = function (result, msg) {
|
|
|
|
if (result.data.error) {
|
|
|
|
vm.alertNotification = {
|
|
|
|
className: 'danger',
|
|
|
|
title: 'Error',
|
|
|
|
hidden: '',
|
|
|
|
message: msg
|
|
|
|
};
|
2017-10-27 23:11:28 +00:00
|
|
|
} else if (result.data.warning) {
|
|
|
|
vm.alertNotification = {
|
|
|
|
className: 'warning',
|
|
|
|
title: 'Warning',
|
|
|
|
hidden: '',
|
|
|
|
message: msg
|
|
|
|
};
|
2017-10-30 21:45:58 +00:00
|
|
|
} else if (result.data.info) {
|
|
|
|
vm.alertNotification = {
|
|
|
|
className: 'info',
|
|
|
|
title: 'Info',
|
|
|
|
hidden: '',
|
|
|
|
message: msg
|
|
|
|
};
|
|
|
|
} else {
|
2017-10-05 19:01:05 +00:00
|
|
|
vm.alertNotification = {
|
|
|
|
className: 'success',
|
|
|
|
title: 'Success',
|
|
|
|
hidden: '',
|
|
|
|
message: msg
|
|
|
|
};
|
|
|
|
}
|
2017-11-01 18:10:39 +00:00
|
|
|
window.scrollTo(0, 0);
|
2017-10-05 19:01:05 +00:00
|
|
|
};
|
|
|
|
|
2017-09-28 21:10:50 +00:00
|
|
|
vm.closeAllOpenActions = function () {
|
|
|
|
$timeout(function() {
|
|
|
|
vm.showInviteContainer = false;
|
|
|
|
vm.showSharesContainer = false;
|
|
|
|
vm.showFilesContainer = false;
|
2017-10-03 22:28:20 +00:00
|
|
|
vm.displayFileTree = false;
|
2017-09-28 21:10:50 +00:00
|
|
|
vm.websiteTiles = false;
|
|
|
|
vm.showBackBtn = false;
|
2017-10-04 22:27:36 +00:00
|
|
|
vm.autoPopulateWebPath = '';
|
2017-09-28 21:10:50 +00:00
|
|
|
}, 150);
|
|
|
|
};
|
2017-08-08 20:54:25 +00:00
|
|
|
}]);
|
2017-09-29 00:04:04 +00:00
|
|
|
|
|
|
|
}());
|
2017-09-29 00:17:33 +00:00
|
|
|
|
2017-09-25 23:15:52 +00:00
|
|
|
app.filter('stringify', function() {
|
2017-09-22 22:17:42 +00:00
|
|
|
function getSerialize (fn, decycle) {
|
|
|
|
var seen = [], keys = [];
|
|
|
|
decycle = decycle || function(key, value) {
|
|
|
|
return '[Parent REFERENCE]: ' + value.id;
|
|
|
|
};
|
|
|
|
return function(key, value) {
|
|
|
|
var ret = value;
|
|
|
|
if (typeof value === 'object' && value) {
|
|
|
|
if (seen.indexOf(value) !== -1)
|
|
|
|
ret = decycle(key, value);
|
|
|
|
else {
|
|
|
|
seen.push(value);
|
|
|
|
keys.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fn) ret = fn(key, ret);
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function getPath (value, seen, keys) {
|
|
|
|
var index = seen.indexOf(value);
|
|
|
|
var path = [ keys[index] ];
|
|
|
|
for (index--; index >= 0; index--) {
|
|
|
|
if (seen[index][ path[0] ] === value) {
|
|
|
|
value = seen[index];
|
|
|
|
path.unshift(keys[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '~' + path.join('.');
|
|
|
|
}
|
|
|
|
function stringify(obj, fn, spaces, decycle) {
|
|
|
|
return JSON.stringify(obj, getSerialize(fn, decycle), spaces);
|
|
|
|
}
|
|
|
|
stringify.getSerialize = getSerialize;
|
|
|
|
return function(ob) {
|
|
|
|
return stringify(ob, undefined, 2);
|
|
|
|
};
|
|
|
|
});
|
2017-10-03 20:49:45 +00:00
|
|
|
|
|
|
|
app.filter('capitalize', function() {
|
2017-10-12 16:41:11 +00:00
|
|
|
return function(input) {
|
|
|
|
return (!!input) ? input.charAt(0).toUpperCase() + input.substr(1).toLowerCase() : '';
|
|
|
|
};
|
2017-10-03 20:49:45 +00:00
|
|
|
});
|
2017-10-12 21:33:40 +00:00
|
|
|
|
|
|
|
app.filter('prettyShareMode', function() {
|
|
|
|
return function(input) {
|
|
|
|
var newArry = [];
|
|
|
|
var arry = input.split(',');
|
|
|
|
arry.forEach(function(action){
|
|
|
|
if (action.includes('w')) {
|
|
|
|
newArry.push('Write');
|
|
|
|
}
|
|
|
|
if (action.includes('r')) {
|
|
|
|
newArry.push('Read');
|
|
|
|
}
|
|
|
|
if (action.includes('x')) {
|
|
|
|
newArry.push('Invite');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return newArry.join(', ');
|
|
|
|
};
|
|
|
|
});
|