diff --git a/front/core/components/autocomplete/index.js b/front/core/components/autocomplete/index.js index 52491f7e0..2539c4ef4 100755 --- a/front/core/components/autocomplete/index.js +++ b/front/core/components/autocomplete/index.js @@ -174,7 +174,6 @@ export default class Autocomplete extends Field { refreshDisplayed() { let display = ''; - let hasTemplate = this.$transclude && this.$transclude.isSlotFilled('tplItem'); if (this._selection && this.showField) { if (this.multiple && Array.isArray(this._selection)) { @@ -182,19 +181,8 @@ export default class Autocomplete extends Field { if (display.length > 0) display += ', '; display += item[this.showField]; } - } else { + } else display = this._selection[this.showField]; - if (hasTemplate) { - let template = this.$transclude(() => {}, null, 'tplItem'); - const element = template[0]; - const description = element.querySelector('.text-secondary'); - if (description) description.remove(); - - const displayElement = angular.element(element); - const displayText = displayElement.text(); - display = this.$interpolate(displayText)(this._selection); - } - } } this.input.value = display; diff --git a/front/core/components/avatar/index.html b/front/core/components/avatar/index.html new file mode 100644 index 000000000..2819e1d50 --- /dev/null +++ b/front/core/components/avatar/index.html @@ -0,0 +1,5 @@ +
+ {{::$ctrl.val && $ctrl.val.charAt(0).toUpperCase()}} +
+
+
diff --git a/front/core/components/avatar/index.js b/front/core/components/avatar/index.js new file mode 100644 index 000000000..e1aede6be --- /dev/null +++ b/front/core/components/avatar/index.js @@ -0,0 +1,63 @@ +import ngModule from '../../module'; +import Component from 'core/lib/component'; +import './style.scss'; + +/** + * Displays colored avatar based on value. + * + * @property {*} val The value + */ +export default class Avatar extends Component { + get val() { + return this._val; + } + + set val(value) { + this._val = value; + + const val = value || ''; + let hash = 0; + for (let i = 0; i < val.length; i++) + hash += val.charCodeAt(i); + const color = '#' + colors[hash % colors.length]; + + const el = this.element; + el.style.backgroundColor = color; + el.title = val; + } +} + +ngModule.vnComponent('vnAvatar', { + template: require('./index.html'), + controller: Avatar, + bindings: { + val: '@?' + }, + transclude: true +}); + +const colors = [ + 'e2553d', // Coral + 'FFA07A', // Salmon + 'FFDAB9', // Peach + 'a17077', // Pink + 'bf0e99', // Pink light + '52a500', // Green chartreuse + '00aeae', // Cian + 'b754cf', // Purple middle + '8a69cd', // Blue lavender + '1fa8a1', // Green ocean + 'DC143C', // Red crimson + '5681cf', // Blue steel + 'FF1493', // Ping intense + '02ba02', // Green lime + '1E90FF', // Blue sky + '8B008B', // Purple dark + 'cc7000', // Orange bright + '00b5b8', // Turquoise + '8B0000', // Red dark + '008080', // Green bluish + '2F4F4F', // Gray board + '7e7e7e', // Gray + '5d5d5d', // Gray dark +]; diff --git a/front/core/components/avatar/style.scss b/front/core/components/avatar/style.scss new file mode 100644 index 000000000..272930821 --- /dev/null +++ b/front/core/components/avatar/style.scss @@ -0,0 +1,32 @@ +@import "variables"; + +vn-avatar { + display: block; + border-radius: 50%; + overflow: hidden; + height: 36px; + width: 36px; + font-size: 22px; + background-color: $color-main; + position: relative; + + & > * { + width: 100%; + height: 100%; + } + & > .letter { + display: flex; + align-items: center; + justify-content: center; + } + & > .image { + position: absolute; + top: 0; + left: 0; + + & > img { + width: 100%; + height: 100%; + } + } +} diff --git a/front/core/components/index.js b/front/core/components/index.js index 44b8beb45..45d182121 100644 --- a/front/core/components/index.js +++ b/front/core/components/index.js @@ -17,6 +17,7 @@ import './pagination/pagination'; import './searchbar/searchbar'; import './scroll-up/scroll-up'; import './autocomplete'; +import './avatar'; import './button'; import './button-menu'; import './calendar'; diff --git a/front/core/components/json-value/index.spec.js b/front/core/components/json-value/index.spec.js index 078080d27..b79d15a5d 100644 --- a/front/core/components/json-value/index.spec.js +++ b/front/core/components/json-value/index.spec.js @@ -1,6 +1,6 @@ import './index'; -describe('Salix Component vnLog', () => { +describe('Component vnJsonValue', () => { let controller; let $scope; let $element; @@ -10,7 +10,7 @@ describe('Salix Component vnLog', () => { beforeEach(inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); - $element = angular.element(''); + $element = angular.element(''); controller = $componentController('vnJsonValue', {$element, $scope}); el = controller.element; })); diff --git a/front/salix/components/log/index.html b/front/salix/components/log/index.html index 3a8744c4b..18c8c82ca 100644 --- a/front/salix/components/log/index.html +++ b/front/salix/components/log/index.html @@ -17,20 +17,16 @@
-
-
- {{::log.user ? log.user.name.charAt(0).toUpperCase() : 'S'}} -
+ val="{{::log.user ? log.user.nickname : 'System'}}" + ng-click="$ctrl.showWorkerDescriptor($event, log)"> -
+
@@ -41,7 +37,7 @@ title="{{::log.creationDate | date:'dd/MM/yyyy HH:mm'}}"> {{::$ctrl.relativeDate(log.creationDate)}}
- + {{::$ctrl.actionsText[log.action]}} @@ -62,7 +58,9 @@ {{::log.changedModelValue}} -
+
@@ -152,13 +150,25 @@ ng-model="filter.userFk" value-field="id" show-field="nickname" - fields="['id', 'name', 'nickname']" + fields="['id', 'name', 'nickname', 'image']" search-function="$ctrl.searchUser($search)" url="{{$ctrl.url}}/{{$ctrl.originId}}/editors" order="nickname"> -
{{nickname}}
-
{{name}}
+
+ + + + +
+
{{::nickname}}
+
{{::name}}
+
+
.user { - position: relative; - border-radius: 50%; - height: 36px; - width: 36px; - display: flex; - align-items: center; - justify-content: center; - overflow: hidden; + & > vn-avatar { + cursor: pointer; - & > * { - width: 100%; - height: 100%; - } &.system { - background-color: $color-main; - } - .user-letter { - font-size: 22px; - display: flex; - align-items: center; - justify-content: center; - } - img { - cursor: pointer; - position: absolute; - top: 0; - left: 0; + background-color: $color-main !important; } } & > .arrow {