diff --git a/front/salix/components/left-menu/left-menu.js b/front/salix/components/left-menu/left-menu.js index da545b291..6bec61775 100644 --- a/front/salix/components/left-menu/left-menu.js +++ b/front/salix/components/left-menu/left-menu.js @@ -45,7 +45,7 @@ export default class LeftMenu { if (acl && !this.aclService.hasAny(acl)) continue; } - + console.log(state, item); let myItem = { icon: item.icon, description: item.description || state.description, diff --git a/modules/worker/back/models/department.json b/modules/worker/back/models/department.json index c3f627e93..7d8d61d73 100644 --- a/modules/worker/back/models/department.json +++ b/modules/worker/back/models/department.json @@ -38,5 +38,17 @@ "hasToMistake": { "type": "number" } + }, + "relations": { + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "clientFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } } } diff --git a/modules/worker/front/department/card/index.html b/modules/worker/front/department/card/index.html new file mode 100644 index 000000000..cc1ad59e4 --- /dev/null +++ b/modules/worker/front/department/card/index.html @@ -0,0 +1,5 @@ + + + + + diff --git a/modules/worker/front/department/card/index.js b/modules/worker/front/department/card/index.js new file mode 100644 index 000000000..288c1a8c3 --- /dev/null +++ b/modules/worker/front/department/card/index.js @@ -0,0 +1,29 @@ +import ngModule from '../module'; +import ModuleCard from 'salix/components/module-card'; + +class Controller extends ModuleCard { + reload() { + const filter = { + fields: ['chatName', 'notificationEmail'], + include: [ + { + relation: 'client', + scope: {fields: ['name']} + }, + { + relation: 'worker', + scope: {fields: ['name']} + } + + ] + }; + + this.$http.get(`Departments/${this.$params.id}`, {filter}) + .then(res => this.department = res.data); + } +} + +ngModule.vnComponent('vnWorkerDepartmentCard', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/worker/front/department/descriptor/index.html b/modules/worker/front/department/descriptor/index.html new file mode 100644 index 000000000..564c2d4da --- /dev/null +++ b/modules/worker/front/department/descriptor/index.html @@ -0,0 +1,90 @@ + + \ No newline at end of file diff --git a/modules/worker/front/department/descriptor/index.js b/modules/worker/front/department/descriptor/index.js new file mode 100644 index 000000000..af57643b7 --- /dev/null +++ b/modules/worker/front/department/descriptor/index.js @@ -0,0 +1,104 @@ +import ngModule from '../module'; +import Descriptor from 'salix/components/descriptor'; + +class Controller extends Descriptor { + constructor($element, $, $rootScope) { + super($element, $); + this.$rootScope = $rootScope; + } + + // get worker() { + // return this.entity; + // } + + // set worker(value) { + // this.entity = value; + + // if (value) + // this.getIsExcluded(); + // } + + // get excluded() { + // return this.entity.excluded; + // } + + // set excluded(value) { + // this.entity.excluded = value; + // } + + // getIsExcluded() { + // this.$http.get(`workerDisableExcludeds/${this.entity.id}/exists`).then(data => { + // this.excluded = data.data.exists; + // }); + // } + + // handleExcluded() { + // if (this.excluded) { + // this.$http.delete(`workerDisableExcludeds/${this.entity.id}`); + // this.excluded = false; + // } else { + // this.$http.post(`workerDisableExcludeds`, {workerFk: this.entity.id, dated: new Date}); + // this.excluded = true; + // } + // } + + // loadData() { + // const filter = { + // include: [ + // { + // relation: 'user', + // scope: { + // fields: ['name'], + // include: { + // relation: 'emailUser', + // scope: { + // fields: ['email'] + // } + // } + // } + // }, { + // relation: 'client', + // scope: { + // fields: ['fi'] + // } + // }, { + // relation: 'sip', + // scope: { + // fields: ['extension'] + // } + // }, { + // relation: 'department', + // scope: { + // include: { + // relation: 'department' + // } + // } + // } + // ] + // }; + + // return this.getData(`Workers/${this.id}`, {filter}) + // .then(res => this.entity = res.data); + // } + + // onUploadResponse() { + // const timestamp = Date.vnNew().getTime(); + // const src = this.$rootScope.imagePath('user', '520x520', this.worker.id); + // const zoomSrc = this.$rootScope.imagePath('user', '1600x1600', this.worker.id); + // const newSrc = `${src}&t=${timestamp}`; + // const newZoomSrc = `${zoomSrc}&t=${timestamp}`; + + // this.$.photo.setAttribute('src', newSrc); + // this.$.photo.setAttribute('zoom-image', newZoomSrc); + // } +} + +Controller.$inject = ['$element', '$scope', '$rootScope']; + +ngModule.vnComponent('vnWorkerDepartmentDescriptor', { + template: require('./index.html'), + controller: Controller, + bindings: { + worker: '<' + } +}); diff --git a/modules/worker/front/department/descriptor/index.spec.js b/modules/worker/front/department/descriptor/index.spec.js new file mode 100644 index 000000000..dfb800415 --- /dev/null +++ b/modules/worker/front/department/descriptor/index.spec.js @@ -0,0 +1,26 @@ +import './index.js'; + +describe('vnWorkerDescriptor', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('worker')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnWorkerDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the worker data into the controller`, () => { + const id = 1; + const response = 'foo'; + + $httpBackend.expectRoute('GET', `Workers/${id}`).respond(response); + controller.id = id; + $httpBackend.flush(); + + expect(controller.worker).toEqual(response); + }); + }); +}); diff --git a/modules/worker/front/department/index/index.html b/modules/worker/front/department/index/index.html index 9afa90e13..894583213 100644 --- a/modules/worker/front/department/index/index.html +++ b/modules/worker/front/department/index/index.html @@ -13,7 +13,7 @@ on-drop="$ctrl.onDrop($dropped, $dragged)" on-drag-start="$ctrl.onDragStart(item)" on-drag-end="$ctrl.onDragEnd(item)" - ui-sref="department.card.summary(item)"> + ng-click="department.card.summary($item)"> {{::item.name}} diff --git a/modules/worker/front/department/index/index.js b/modules/worker/front/department/index/index.js index 178299362..6b7ab18da 100644 --- a/modules/worker/front/department/index/index.js +++ b/modules/worker/front/department/index/index.js @@ -77,7 +77,7 @@ class Controller extends Section { } } -ngModule.vnComponent('vnWorkerDepartment', { +ngModule.vnComponent('vnWorkerDepartmentIndex', { template: require('./index.html'), controller: Controller }); diff --git a/modules/worker/front/department/main/index.html b/modules/worker/front/department/main/index.html new file mode 100644 index 000000000..3ab993e83 --- /dev/null +++ b/modules/worker/front/department/main/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/modules/worker/front/department/main/index.js b/modules/worker/front/department/main/index.js new file mode 100644 index 000000000..75110f749 --- /dev/null +++ b/modules/worker/front/department/main/index.js @@ -0,0 +1,9 @@ +import ngModule from '../module'; +import ModuleMain from 'salix/components/module-main'; + +export default class Worker extends ModuleMain {} + +ngModule.vnComponent('vnWorkerDepartment', { + controller: Worker, + template: require('./index.html') +}); diff --git a/modules/worker/front/department/routes.json b/modules/worker/front/department/routes.json deleted file mode 100644 index f6fd46367..000000000 --- a/modules/worker/front/department/routes.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "module": "deparment", - "name": "Departments", - "icon" : "work", - "validations" : true, - "dependencies": ["account"], - "menus": { - "main": [ - {"state": "deparment.index", "icon": "icon-worker"} - ], - "card": [ - {"state": "department.card.basicData", "icon": "settings"}, - { - "icon": "icon-wiki", - "external":true, - "url": "http://wiki.verdnatura.es", - "description": "Wikipedia" - }, - {"state": "worker.card.workerLog", "icon": "history"} - ] - }, - "routes": [ - { - "url": "/worker", - "state": "worker", - "abstract": true, - "component": "vn-worker", - "description": "Workers" - }, { - "url": "/index?q", - "state": "worker.index", - "component": "vn-worker-index", - "description": "Workers" - }, { - "url" : "/summary", - "state": "worker.card.summary", - "component": "vn-worker-summary", - "description": "Summary", - "params": { - "worker": "$ctrl.worker" - } - }, { - "url": "/:id", - "state": "worker.card", - "component": "vn-worker-card", - "abstract": true, - "description": "Detail" - }, { - "url": "/basic-data", - "state": "worker.card.basicData", - "component": "vn-worker-basic-data", - "description": "Basic data", - "params": { - "worker": "$ctrl.worker" - }, - "acl": ["hr"] - }, { - "url" : "/log", - "state": "worker.card.workerLog", - "component": "vn-worker-log", - "description": "Log", - "acl": ["salesAssistant"] - }, { - "url": "/index", - "state": "worker.card.note.index", - "component": "vn-worker-note", - "description": "Notes", - "params": { - "worker": "$ctrl.worker" - }, - "acl": ["hr"] - }, { - "url": "/create", - "state": "worker.card.note.create", - "component": "vn-note-worker-create", - "description": "New note" - }, - { - "url": "/index", - "state": "worker.card.dms.index", - "component": "vn-worker-dms-index", - "description": "My documentation", - "acl": ["employee"] - }, - { - "url": "/create", - "state": "worker.card.dms.create", - "component": "vn-worker-dms-create", - "description": "Upload file", - "params": { - "worker": "$ctrl.worker" - }, - "acl": ["hr"] - }, - { - "url": "/create", - "state": "worker.create", - "component": "vn-worker-create", - "description": "New worker", - "acl": ["hr"] - } - ] -} diff --git a/modules/worker/front/department/summary/index.html b/modules/worker/front/department/summary/index.html index de8710a6d..3cffe2f71 100644 --- a/modules/worker/front/department/summary/index.html +++ b/modules/worker/front/department/summary/index.html @@ -1,18 +1,18 @@
- - {{worker.firstName}} {{worker.lastName}} + {{department.name}}

+ ui-sref="department.card.basicData({id:$ctrl.department.id})"> Basic data

@@ -21,34 +21,28 @@ ng-show="!$ctrl.isHr"> Basic data - + - + - + + label="Boss:"> {{::worker.boss.nickname}} - + - - - - - +
@@ -68,6 +62,6 @@
- - + + diff --git a/modules/worker/front/department/summary/index.js b/modules/worker/front/department/summary/index.js index c2ad107d5..ede559d18 100644 --- a/modules/worker/front/department/summary/index.js +++ b/modules/worker/front/department/summary/index.js @@ -2,56 +2,28 @@ import ngModule from '../module'; import Summary from 'salix/components/summary'; class Controller extends Summary { - get worker() { - return this._worker; + get department() { + return this._department; } - set worker(value) { - this._worker = value; - this.$.worker = null; + set department(value) { + this._department = value; + this.$.department = null; if (!value) return; - const query = `Workers/${value.id}`; + const query = `Departments/${value.id}`; const filter = { + fields: ['chatName', 'notificationEmail'], include: [ - { - relation: 'user', - scope: { - fields: ['name', 'roleFk'], - include: [{ - relation: 'role', - scope: { - fields: ['name'] - } - }, - { - relation: 'emailUser', - scope: { - fields: ['email'] - } - }] - } - }, { relation: 'client', - scope: {fields: ['fi', 'phone']} + scope: {fields: ['name']} }, { - relation: 'boss', - scope: {fields: ['id', 'nickname']} - }, - { - relation: 'sip', - scope: {fields: ['extension']} - }, - { - relation: 'department', - scope: { - include: { - relation: 'department' - } - } + relation: 'worker', + scope: {fields: ['name']} } + ] }; @@ -65,7 +37,7 @@ class Controller extends Summary { } } -ngModule.vnComponent('vnWorkerSummary', { +ngModule.vnComponent('vnDepartmentSummary', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index 6817d0cef..34a8a14e3 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -7,7 +7,7 @@ "menus": { "main": [ {"state": "worker.index", "icon": "icon-worker"}, - {"state": "worker.department", "icon": "work"} + {"state": "worker.department.index", "icon": "work"} ], "card": [ {"state": "worker.card.basicData", "icon": "settings"}, @@ -118,11 +118,31 @@ "worker": "$ctrl.worker" } }, { - "url" : "/department/department", + "url": "/department", "state": "worker.department", - "component": "vn-worker-department", - "description": "Departments", + "abstract": true, + "description":"Departments", + "component": "ui-view" + }, { + "url": "/:id", + "state": "worker.department.card", + "component": "vn-worker-department-card", + "abstract": true, + "description": "Detail" + }, { + "url" : "/index", + "state": "worker.department.index", + "component": "vn-worker-department-index", + "description": "Department", "acl": ["hr"] + }, { + "url" : "/summary", + "state": "worker.department.card.summary", + "component": "vn-worker-department-summary", + "description": "Summary", + "params": { + "department": "$ctrl.department" + } }, { "url": "/dms", "state": "worker.card.dms",