2017-09-19 17:58:33 +01:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { inject as service } from '@ember/service';
|
2017-09-19 17:58:33 +01:00
|
|
|
import NotifierMixin from '../../mixins/notifier';
|
2017-09-21 15:48:00 +01:00
|
|
|
import TooltipMixin from '../../mixins/tooltip';
|
2017-09-21 16:27:36 +01:00
|
|
|
import DropdownMixin from '../../mixins/dropdown';
|
2017-09-19 17:58:33 +01:00
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
export default Component.extend(NotifierMixin, TooltipMixin, DropdownMixin, {
|
2017-09-21 15:48:00 +01:00
|
|
|
userService: service('user'),
|
2017-09-19 17:58:33 +01:00
|
|
|
categoryService: service('category'),
|
|
|
|
appMeta: service(),
|
|
|
|
store: service(),
|
|
|
|
newCategory: '',
|
2017-11-27 15:38:39 +00:00
|
|
|
deleteId: '',
|
2017-09-21 16:27:36 +01:00
|
|
|
dropdown: null,
|
2017-09-21 15:48:00 +01:00
|
|
|
users: [],
|
2017-09-19 17:58:33 +01:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
2017-10-04 13:27:48 -04:00
|
|
|
this._super(...arguments);
|
2017-11-27 15:38:39 +00:00
|
|
|
this.renderTooltips();
|
2017-10-04 13:27:48 -04:00
|
|
|
this.load();
|
2017-09-21 15:48:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
2017-10-04 13:27:48 -04:00
|
|
|
this._super(...arguments);
|
2017-11-27 15:38:39 +00:00
|
|
|
this.removeTooltips();
|
2017-09-21 15:48:00 +01:00
|
|
|
},
|
|
|
|
|
2017-09-19 17:58:33 +01:00
|
|
|
load() {
|
2017-09-21 15:48:00 +01:00
|
|
|
// get categories
|
2017-09-19 17:58:33 +01:00
|
|
|
this.get('categoryService').getAll(this.get('folder.id')).then((c) => {
|
|
|
|
this.set('category', c);
|
2017-09-21 15:48:00 +01:00
|
|
|
|
2017-09-21 18:59:43 +01:00
|
|
|
// get summary of documents and users for each category in space
|
|
|
|
this.get('categoryService').getSummary(this.get('folder.id')).then((s) => {
|
|
|
|
c.forEach((cat) => {
|
|
|
|
let docs = _.findWhere(s, {categoryId: cat.get('id'), type: 'documents'});
|
|
|
|
let docCount = is.not.undefined(docs) ? docs.count : 0;
|
|
|
|
|
|
|
|
let users = _.findWhere(s, {categoryId: cat.get('id'), type: 'users'});
|
|
|
|
let userCount = is.not.undefined(users) ? users.count : 0;
|
|
|
|
|
|
|
|
cat.set('documents', docCount);
|
|
|
|
cat.set('users', userCount);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-21 15:48:00 +01:00
|
|
|
// get users that this space admin user can see
|
2017-09-22 10:22:52 +01:00
|
|
|
this.get('userService').getSpaceUsers(this.get('folder.id')).then((users) => {
|
2017-09-21 15:48:00 +01:00
|
|
|
// set up Everyone user
|
|
|
|
let u = {
|
|
|
|
orgId: this.get('folder.orgId'),
|
|
|
|
folderId: this.get('folder.id'),
|
|
|
|
userId: '',
|
|
|
|
firstname: 'Everyone',
|
|
|
|
lastname: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
let data = this.get('store').normalize('user', u)
|
|
|
|
users.pushObject(this.get('store').push(data));
|
|
|
|
|
|
|
|
users = users.sortBy('firstname', 'lastname');
|
|
|
|
this.set('users', users);
|
|
|
|
});
|
2017-09-19 17:58:33 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setEdit(id, val) {
|
|
|
|
let cats = this.get('category');
|
|
|
|
let cat = cats.findBy('id', id);
|
|
|
|
|
|
|
|
if (is.not.undefined(cat)) {
|
|
|
|
cat.set('editMode', val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cat;
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2017-11-27 15:38:39 +00:00
|
|
|
onAdd(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2017-09-19 17:58:33 +01:00
|
|
|
let cat = this.get('newCategory');
|
|
|
|
|
|
|
|
if (cat === '') {
|
2017-11-27 15:38:39 +00:00
|
|
|
$('#new-category-name').addClass('is-invalid').focus();
|
2017-09-19 17:58:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-27 15:38:39 +00:00
|
|
|
$('#new-category-name').removeClass('is-invalid').focus();
|
2017-09-19 17:58:33 +01:00
|
|
|
this.set('newCategory', '');
|
|
|
|
|
|
|
|
let c = {
|
|
|
|
category: cat,
|
|
|
|
folderId: this.get('folder.id')
|
|
|
|
};
|
|
|
|
|
|
|
|
this.get('categoryService').add(c).then(() => {
|
|
|
|
this.load();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-11-27 15:38:39 +00:00
|
|
|
onShowDelete(id) {
|
|
|
|
let cat = this.get('category').findBy('id', id);
|
|
|
|
this.set('deleteId', cat.get('id'));
|
|
|
|
|
|
|
|
$('#category-delete-modal').modal('dispose');
|
|
|
|
$('#category-delete-modal').modal({show: true});
|
|
|
|
},
|
|
|
|
|
|
|
|
onDelete() {
|
|
|
|
$('#category-delete-modal').modal('hide');
|
|
|
|
$('#category-delete-modal').modal('dispose');
|
|
|
|
|
|
|
|
this.get('categoryService').delete(this.get('deleteId')).then(() => {
|
2017-09-19 17:58:33 +01:00
|
|
|
this.load();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onEdit(id) {
|
|
|
|
this.setEdit(id, true);
|
2017-11-27 16:17:17 +00:00
|
|
|
this.removeTooltips();
|
2017-09-19 17:58:33 +01:00
|
|
|
},
|
|
|
|
|
2017-09-21 15:48:00 +01:00
|
|
|
onEditCancel(id) {
|
2017-09-19 17:58:33 +01:00
|
|
|
this.setEdit(id, false);
|
2017-09-19 18:55:33 +01:00
|
|
|
this.load();
|
2017-11-27 16:17:17 +00:00
|
|
|
this.renderTooltips();
|
2017-09-19 17:58:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onSave(id) {
|
2017-09-19 18:55:33 +01:00
|
|
|
let cat = this.setEdit(id, true);
|
|
|
|
if (cat.get('category') === '') {
|
2017-11-27 15:38:39 +00:00
|
|
|
$('#edit-category-' + cat.get('id')).addClass('is-invalid').focus();
|
|
|
|
return false;
|
2017-09-19 18:55:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cat = this.setEdit(id, false);
|
2017-11-27 15:38:39 +00:00
|
|
|
$('#edit-category-' + cat.get('id')).removeClass('is-invalid');
|
2017-09-19 17:58:33 +01:00
|
|
|
|
|
|
|
this.get('categoryService').save(cat).then(() => {
|
|
|
|
this.load();
|
|
|
|
});
|
2017-11-27 16:17:17 +00:00
|
|
|
|
|
|
|
this.renderTooltips();
|
2017-09-21 15:48:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onShowAccessPicker(catId) {
|
2017-11-27 15:38:39 +00:00
|
|
|
this.set('showCategoryAccess', true);
|
|
|
|
|
2017-09-21 15:48:00 +01:00
|
|
|
let users = this.get('users');
|
|
|
|
let category = this.get('category').findBy('id', catId);
|
|
|
|
|
2017-09-21 18:59:43 +01:00
|
|
|
this.get('categoryService').getPermissions(category.get('id')).then((viewers) => {
|
2017-09-21 15:48:00 +01:00
|
|
|
// mark those users as selected that have already been given permission
|
|
|
|
// to see the current category;
|
|
|
|
users.forEach((user) => {
|
2017-10-04 13:27:48 -04:00
|
|
|
let userId = user.get('id');
|
2017-09-21 18:59:43 +01:00
|
|
|
let selected = viewers.isAny('whoId', userId);
|
2017-09-21 15:48:00 +01:00
|
|
|
user.set('selected', selected);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('categoryUsers', users);
|
|
|
|
this.set('currentCategory', category);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onGrantAccess() {
|
2017-11-27 15:38:39 +00:00
|
|
|
this.set('showCategoryAccess', false);
|
|
|
|
|
2017-09-22 08:52:11 +01:00
|
|
|
let folder = this.get('folder');
|
2017-09-21 15:48:00 +01:00
|
|
|
let category = this.get('currentCategory');
|
|
|
|
let users = this.get('categoryUsers').filterBy('selected', true);
|
|
|
|
let viewers = [];
|
|
|
|
|
|
|
|
users.forEach((user) => {
|
2017-09-21 18:59:43 +01:00
|
|
|
let userId = user.get('id');
|
|
|
|
|
2017-09-21 15:48:00 +01:00
|
|
|
let v = {
|
|
|
|
orgId: this.get('folder.orgId'),
|
|
|
|
folderId: this.get('folder.id'),
|
|
|
|
categoryId: category.get('id'),
|
2017-09-21 18:59:43 +01:00
|
|
|
userId: userId
|
2017-09-21 15:48:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
viewers.push(v);
|
|
|
|
});
|
|
|
|
|
2017-09-22 08:52:11 +01:00
|
|
|
this.get('categoryService').setViewers(folder.get('id'), category.get('id'), viewers).then(() => {
|
2017-09-21 18:59:43 +01:00
|
|
|
this.load();
|
|
|
|
});
|
2017-09-19 17:58:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|