Skip to content

Commit

Permalink
refactor tag modal for creation and update
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Aug 23, 2020
1 parent 347ff5b commit 91760ae
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 43 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"TAG":{
"TITLE":"Tag",
"LABEL":"Tag",
"TAGS":"Tags",
"ADD":"Add Tag",
"EDIT":"Edit Tag",
"DELETE":"Delete Tag",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"TAG":{
"TITLE":"Etiquette",
"LABEL":"Etiquette",
"TAGS":"Etiquettes",
"ADD":"Ajouter étiquette",
"EDIT":"Editer étiquette",
"DELETE":"Supprimer étiquette",
Expand Down
6 changes: 4 additions & 2 deletions client/src/js/components/bhTagSelect/bhTagSelect.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
class="form-group"
ng-class="{ 'has-error' : TagForm.$submitted && TagForm.tagUuids.$invalid }">

<label class="control-label" translate>
{{ $ctrl.label }}
<label class="control-label">
<span translate>{{ $ctrl.label }}</span>&nbsp;
<a style="cursor: pointer;" ng-click="$ctrl.createUpdateTagsModal()" translate>TAG.ADD</a>
</label>

<ng-transclude></ng-transclude>

<ui-select
name="tagUuids"
ng-model="$ctrl.tagUuids"
Expand Down
12 changes: 9 additions & 3 deletions client/src/js/components/bhTagSelect/bhTagSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ angular.module('bhima.components')
},
});

TagSelectController.$inject = ['TagService', 'NotifyService'];
TagSelectController.$inject = ['$rootScope', 'TagService', 'NotifyService'];

/**
* Tag selection component
*/
function TagSelectController(Tags, Notify) {
function TagSelectController($rootScope, Tags, Notify) {
const $ctrl = this;

$ctrl.createUpdateTagsModal = Tags.createUpdateTagsModal;

$rootScope.$on('TAGS_CHANGED', () => {
loadTags();
});

$ctrl.$onInit = function onInit() {
$ctrl.label = $ctrl.label || 'TAG.LABEL';
$ctrl.label = $ctrl.label || 'TAG.TAGS';
$ctrl.tagUuids = $ctrl.tagUuids || [];
loadTags();
};
Expand Down
22 changes: 0 additions & 22 deletions client/src/js/services/TagService.js

This file was deleted.

4 changes: 2 additions & 2 deletions client/src/modules/tags/modal/createUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ angular.module('bhima.controllers')
.controller('TagsModalController', TagsModalController);

TagsModalController.$inject = [
'data', '$state', 'TagsService', 'NotifyService',
'data', 'TagService', 'NotifyService',
'$uibModalInstance', '$rootScope', 'ColorService',
];

function TagsModalController(
data, $state, TagsService, Notify, Instance, $rootScope, Colors,
data, TagsService, Notify, Instance, $rootScope, Colors,
) {
const vm = this;
vm.colors = Colors.list.map(e => {
Expand Down
10 changes: 2 additions & 8 deletions client/src/modules/tags/tags.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('bhima.controllers')
.controller('TagsController', TagsController);

TagsController.$inject = [
'$uibModal', 'TagsService', 'ModalService',
'$uibModal', 'TagService', 'ModalService',
'NotifyService', 'uiGridConstants', '$rootScope',
];

Expand All @@ -11,13 +11,7 @@ function TagsController($uibModal, Tags, Modal, Notify, uiGridConstants, $rootSc

vm.canEditTags = false;

vm.createUpdateTagsModal = (tag) => {
$uibModal.open({
templateUrl : 'modules/tags/modal/createUpdate.html',
controller : 'TagsModalController as ModalCtrl',
resolve : { data : () => tag },
});
};
vm.createUpdateTagsModal = Tags.createUpdateTagsModal;

vm.remove = function remove(uuid) {
const message = 'FORM.DIALOGS.CONFIRM_ACTION';
Expand Down
28 changes: 22 additions & 6 deletions client/src/modules/tags/tags.service.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
angular.module('bhima.services')
.service('TagsService', TagsService);
.service('TagService', TagService);

TagsService.$inject = ['PrototypeApiService'];
TagService.$inject = ['PrototypeApiService', 'util', '$uibModal'];

/**
* Tags Service
* @class TagService
* @extends PrototypeApiService
*
* A service wrapper for the /tags HTTP endpoint.
* @description
* Encapsulates common requests to the /tags/ URL.
*/
function TagsService(Api) {
const service = new Api('/tags/');
function TagService(Api, util, $uibModal) {
const baseUrl = '/tags/';
const service = new Api(baseUrl);
service.types = new Api(baseUrl.concat('types/'));

const tagKeys = ['uuid', 'name', 'color'];
service.clean = tag => util.maskObjectFromKeys(tag, tagKeys);

service.createUpdateTagsModal = (tag) => {
$uibModal.open({
templateUrl : 'modules/tags/modal/createUpdate.html',
controller : 'TagsModalController as ModalCtrl',
resolve : { data : () => tag },
});
};

return service;
}

0 comments on commit 91760ae

Please sign in to comment.