1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 15:49:44 +02:00

space categorty management

This commit is contained in:
Harvey Kandola 2017-09-19 17:58:33 +01:00
parent a86d52388e
commit 4874d23f15
19 changed files with 915 additions and 40 deletions

View file

@ -0,0 +1,91 @@
// 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
import Ember from 'ember';
import NotifierMixin from '../../mixins/notifier';
const {
inject: { service }
} = Ember;
export default Ember.Component.extend(NotifierMixin, {
folderService: service('folder'),
categoryService: service('category'),
appMeta: service(),
store: service(),
newCategory: '',
didReceiveAttrs() {
this.load();
},
load() {
this.get('categoryService').getAll(this.get('folder.id')).then((c) => {
this.set('category', c);
});
},
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: {
onAdd() {
let cat = this.get('newCategory');
if (cat === '') {
$('#new-category-name').addClass('error').focus();
return;
}
$('#new-category-name').removeClass('error').focus();
this.set('newCategory', '');
let c = {
category: cat,
folderId: this.get('folder.id')
};
this.get('categoryService').add(c).then(() => {
this.load();
});
},
onDelete(id) {
this.get('categoryService').delete(id).then(() => {
this.load();
});
},
onEdit(id) {
this.setEdit(id, true);
},
onCancel(id) {
this.setEdit(id, false);
},
onSave(id) {
let cat = this.setEdit(id, false);
this.get('categoryService').save(cat).then(() => {
this.load();
});
}
}
});

View file

@ -0,0 +1,21 @@
// 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
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
orgId: attr('string'),
folderId: attr('string'),
category: attr('string'),
created: attr(),
revised: attr()
});

View file

@ -1 +1 @@
{{folder/invite-user folders=model.folders folder=model.folder}}
{{folder/category-admin folders=model.folders folder=model.folder}}

View file

@ -0,0 +1,87 @@
// 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
import Ember from 'ember';
import BaseService from '../services/base';
const {
inject: { service }
} = Ember;
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'
});
}
});

View file

@ -34,6 +34,41 @@
}
}
}
}
}
.category-table {
padding: 0;
margin: 0 0 0 20px;
width: 60%;
> .row {
margin: 15px 0;
padding: 8px 10px;
background-color: $color-off-white;
@include border-radius(2px);
> .category {
font-size: 1.2rem;
vertical-align: bottom;
display: inline-block;
margin-top: 8px;
}
> .action {
display: inline-block;
}
> .input-control {
margin: 0;
display: inline-block;
> input {
margin: 0;
padding: 0;
font-size: 1.2rem;
}
}
}
}
}

View file

@ -0,0 +1,53 @@
<div class="space-settings">
<div class="panel">
<div class="form-header">
<div class="title">Categories</div>
<div class="tip">Organize and secure document access with optional categories</div>
</div>
<form id="category-form" {{action 'onAdd' on='submit'}}>
<div class="input-control">
<div class="category-table">
{{#each category as |cat|}}
<div class="row">
{{#if cat.editMode}}
<div class="input-control input-transparent width-60">
{{focus-input id=(concat 'edit-category-' cat.id) type="text" value=cat.category class="input-inline"}}
</div>
{{else}}
<div class="category">{{cat.category}}</div>
{{/if}}
<div class="pull-right">
{{#if cat.editMode}}
<button type="submit" class="round-button-mono" {{action 'onSave' cat.id}}>
<i class="material-icons color-green">check</i>
</button>
<div class="round-button-mono" {{action 'onCancel' cat.id}}>
<i class="material-icons color-gray">close</i>
</div>
{{else}}
<div {{action 'onEdit' cat.id}} class="action round-button-mono button-white">
<i class="material-icons">edit</i>
</div>
<div id="{{concat 'delete-category-' cat.id}}" class="action round-button-mono button-white">
<i class="material-icons">delete</i>
</div>
{{#dropdown-dialog target=(concat 'delete-category-' cat.id) position="bottom right" button="Delete" color="flat-red" onAction=(action 'onDelete' cat.id)}}
<p>Are you sure you want to delete category <b>{{cat.category}}?</b></p>
{{/dropdown-dialog}}
{{/if}}
</div>
</div>
{{else}}
<div class="margin-top-30"><i>No categories defined yet</i></div>
{{/each}}
</div>
<div class="input-control margin-top-50">
<label>Add Category</label>
<div class="tip">Provide a short name</div>
{{focus-input id="new-category-name" type="text" value=newCategory}}
</div>
</div>
<div class="regular-button button-blue" {{action 'onAdd'}}>add</div>
</form>
</div>
</div>