Create TagService

This new Service can be used anywhere that needs a credentials tag and
can be expanded upon to include other helpful tag methods as needed.
This commit is contained in:
kialam
2018-05-31 13:40:51 -04:00
parent 62f4beddb2
commit f49b61ecfa
5 changed files with 32 additions and 6 deletions

View File

@@ -168,6 +168,7 @@
display: flex; display: flex;
margin-left: @at-margin-left-list-row-item-tag-container; margin-left: @at-margin-left-list-row-item-tag-container;
flex-wrap: wrap; flex-wrap: wrap;
line-height: initial;
} }
.at-RowItem-tag { .at-RowItem-tag {

View File

@@ -2,7 +2,8 @@ import { TRUNCATED, TRUNCATE_LENGTH } from './constants';
const templateUrl = require('~components/toggle/toggle-tag.partial.html'); const templateUrl = require('~components/toggle/toggle-tag.partial.html');
function controller () { function controller ($scope, TagService) {
const { tags } = $scope;
const vm = this; const vm = this;
vm.truncatedLength = TRUNCATE_LENGTH; vm.truncatedLength = TRUNCATE_LENGTH;
vm.truncated = TRUNCATED; vm.truncated = TRUNCATED;
@@ -10,8 +11,16 @@ function controller () {
vm.toggle = () => { vm.toggle = () => {
vm.truncated = !vm.truncated; vm.truncated = !vm.truncated;
}; };
vm.tags = [];
// build credentials from tags object
Object.keys(tags).forEach(key => {
vm.tags.push(TagService.buildCredentialTag(tags[key]));
});
} }
controller.$inject = ['$scope', 'TagService'];
function atToggleTag () { function atToggleTag () {
return { return {
restrict: 'E', restrict: 'E',

View File

@@ -1,13 +1,13 @@
<div class="ToggleComponent-wrapper"> <div class="ToggleComponent-wrapper">
<div ng-show="vm.truncated" class="ToggleComponent-container"> <div ng-show="vm.truncated" class="ToggleComponent-container">
<div ng-repeat="tag in tags | limitTo: vm.truncatedLength"> <div ng-repeat="tag in vm.tags | limitTo: vm.truncatedLength">
<at-tag tag="tag.name" icon="{{ tag.kind }}"></at-tag> <at-tag tag="tag.value" icon="{{ tag.icon }}" link="{{ tag.link }}"></at-tag>
</div> </div>
<button class="ToggleComponent-button" ng-click="vm.toggle()">VIEW MORE</button> <button class="ToggleComponent-button" ng-click="vm.toggle()">VIEW MORE</button>
</div> </div>
<div ng-show="!vm.truncated" class="ToggleComponent-container"> <div ng-show="!vm.truncated" class="ToggleComponent-container">
<div ng-repeat="tag in tags"> <div ng-repeat="tag in vm.tags">
<at-tag tag="tag.name" icon="{{ tag.kind }}"></at-tag> <at-tag tag="tag.value" icon="{{ tag.icon }}" link="{{ tag.link }}"></at-tag>
</div> </div>
<button class="ToggleComponent-button" ng-click="vm.toggle()">VIEW LESS</button> <button class="ToggleComponent-button" ng-click="vm.toggle()">VIEW LESS</button>
</div> </div>

View File

@@ -2,6 +2,7 @@ import AppStrings from '~services/app.strings';
import BaseStringService from '~services/base-string.service'; import BaseStringService from '~services/base-string.service';
import CacheService from '~services/cache.service'; import CacheService from '~services/cache.service';
import EventService from '~services/event.service'; import EventService from '~services/event.service';
import TagService from '~services/tag.service';
const MODULE_NAME = 'at.lib.services'; const MODULE_NAME = 'at.lib.services';
@@ -12,6 +13,7 @@ angular
.service('AppStrings', AppStrings) .service('AppStrings', AppStrings)
.service('BaseStringService', BaseStringService) .service('BaseStringService', BaseStringService)
.service('CacheService', CacheService) .service('CacheService', CacheService)
.service('EventService', EventService); .service('EventService', EventService)
.service('TagService', TagService);
export default MODULE_NAME; export default MODULE_NAME;

View File

@@ -0,0 +1,14 @@
function TagService (strings, $filter) {
this.buildCredentialTag = (credential) => {
const icon = `${credential.kind}`;
const link = `/#/credentials/${credential.id}`;
const tooltip = strings.get('tooltips.CREDENTIAL');
const value = $filter('sanitize')(credential.name);
return { icon, link, tooltip, value };
};
}
TagService.$inject = ['OutputStrings', '$filter'];
export default TagService;