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 { inject as service } from '@ember/service';
|
2017-09-19 17:58:33 +01:00
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
import BaseService from '../services/base';
|
2017-09-19 17:58:33 +01:00
|
|
|
|
|
|
|
export default BaseService.extend({
|
|
|
|
sessionService: service('session'),
|
|
|
|
ajax: service(),
|
|
|
|
localStorage: service(),
|
|
|
|
store: service(),
|
|
|
|
|
|
|
|
// Add category to space
|
|
|
|
add(payload) {
|
|
|
|
return this.get('ajax').post(`category`, {
|
|
|
|
contentType: 'json',
|
|
|
|
data: JSON.stringify(payload)
|
|
|
|
}).then((category) => {
|
|
|
|
let data = this.get('store').normalize('category', category);
|
|
|
|
return this.get('store').push(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns space categories viewable by user.
|
|
|
|
getUserVisible(spaceId) {
|
|
|
|
return this.get('ajax').request(`category/space/${spaceId}`, {
|
|
|
|
method: 'GET'
|
|
|
|
}).then((response) => {
|
|
|
|
let data = [];
|
|
|
|
|
|
|
|
data = response.map((obj) => {
|
|
|
|
let data = this.get('store').normalize('category', obj);
|
|
|
|
return this.get('store').push(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns all space categories for admin user.
|
|
|
|
getAll(spaceId) {
|
|
|
|
return this.get('ajax').request(`category/space/${spaceId}?filter=all`, {
|
|
|
|
method: 'GET'
|
|
|
|
}).then((response) => {
|
|
|
|
let data = [];
|
|
|
|
|
|
|
|
data = response.map((obj) => {
|
|
|
|
let data = this.get('store').normalize('category', obj);
|
|
|
|
return this.get('store').push(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Updates an existing category.
|
|
|
|
save(category) {
|
|
|
|
let id = category.get('id');
|
|
|
|
|
|
|
|
return this.get('ajax').request(`category/${id}`, {
|
|
|
|
method: 'PUT',
|
|
|
|
contentType: 'json',
|
|
|
|
data: JSON.stringify(category)
|
|
|
|
}).then((category) => {
|
|
|
|
let data = this.get('store').normalize('category', category);
|
|
|
|
return this.get('store').push(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
delete(categoryId) {
|
|
|
|
return this.get('ajax').request(`category/${categoryId}`, {
|
|
|
|
method: 'DELETE'
|
|
|
|
});
|
2017-09-21 15:48:00 +01:00
|
|
|
},
|
|
|
|
|
2017-09-21 18:59:43 +01:00
|
|
|
// Get viewer permission records for given category
|
|
|
|
getPermissions(categoryId) {
|
2017-09-21 15:48:00 +01:00
|
|
|
return this.get('ajax').request(`category/${categoryId}/permission`, {
|
|
|
|
method: 'GET'
|
2017-09-21 18:59:43 +01:00
|
|
|
}).then((response) => {
|
|
|
|
return response;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Get list of users who can see given category
|
|
|
|
getUsers(categoryId) {
|
|
|
|
return this.get('ajax').request(`category/${categoryId}/user`, {
|
|
|
|
method: 'GET'
|
2017-09-21 15:48:00 +01:00
|
|
|
}).then((response) => {
|
|
|
|
let data = [];
|
|
|
|
|
|
|
|
data = response.map((obj) => {
|
|
|
|
let data = this.get('store').normalize('user', obj);
|
|
|
|
return this.get('store').push(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Save list of users who can see given category
|
2017-09-22 08:52:11 +01:00
|
|
|
setViewers(spaceId, categoryId, viewers) {
|
|
|
|
return this.get('ajax').request(`category/${categoryId}/permission?space=${spaceId}`, {
|
2017-09-21 15:48:00 +01:00
|
|
|
method: 'PUT',
|
|
|
|
contentType: 'json',
|
|
|
|
data: JSON.stringify(viewers)
|
|
|
|
});
|
|
|
|
},
|
2017-09-21 18:59:43 +01:00
|
|
|
|
|
|
|
// Get count of documents and users associated with each category in given space.
|
|
|
|
getSummary(spaceId) {
|
|
|
|
return this.get('ajax').request(`category/space/${spaceId}/summary`, {
|
|
|
|
method: 'GET'
|
|
|
|
}).then((response) => {
|
|
|
|
return response;
|
|
|
|
});
|
2017-09-22 17:23:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
setCategoryMembership(categories, mode) {
|
|
|
|
return this.get('ajax').request(`category/member?mode=${mode}`, {
|
|
|
|
method: 'POST',
|
|
|
|
contentType: 'json',
|
|
|
|
data: JSON.stringify(categories)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Get categories associated with a document.
|
|
|
|
getDocumentCategories(documentId) {
|
|
|
|
return this.get('ajax').request(`category/document/${documentId}`, {
|
|
|
|
method: 'GET'
|
|
|
|
}).then((response) => {
|
|
|
|
return response;
|
|
|
|
});
|
2017-09-26 16:30:16 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getSpaceCategoryMembership(spaceId) {
|
|
|
|
return this.get('ajax').request(`category/member/space/${spaceId}`, {
|
|
|
|
method: 'GET'
|
|
|
|
}).then((response) => {
|
|
|
|
return response;
|
|
|
|
});
|
2017-10-08 20:53:25 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// fetchXXX represents UI specific bulk data loading designed to
|
|
|
|
// reduce network traffic and boost app performance.
|
|
|
|
// This method that returns:
|
|
|
|
// 1. getUserVisible()
|
|
|
|
// 2. getSummary()
|
|
|
|
// 3. getSpaceCategoryMembership()
|
|
|
|
fetchSpaceData(spaceId) {
|
|
|
|
return this.get('ajax').request(`fetch/category/space/${spaceId}`, {
|
|
|
|
method: 'GET'
|
|
|
|
}).then((response) => {
|
|
|
|
let data = {
|
|
|
|
category: [],
|
|
|
|
membership: [],
|
|
|
|
summary: []
|
|
|
|
};
|
|
|
|
|
|
|
|
let cats = response.category.map((obj) => {
|
|
|
|
let data = this.get('store').normalize('category', obj);
|
|
|
|
return this.get('store').push(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
data.category = cats;
|
|
|
|
data.membership = response.membership;
|
|
|
|
data.summary = response.summary;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
2017-09-21 18:59:43 +01:00
|
|
|
}
|
2017-09-19 17:58:33 +01:00
|
|
|
});
|