From 3b5c27096bd2d9cd5aab10bc01d149fa00d9ffe4 Mon Sep 17 00:00:00 2001 From: bgamard Date: Sat, 7 Mar 2020 17:46:40 +0100 Subject: [PATCH] Closes #350: better relations widget --- .../src/app/docs/directive/SelectRelation.js | 36 +++++++++---------- ...directive.selectionrelation.typeahead.html | 4 +++ .../docs/directive.selectrelation.html | 3 +- .../src/partial/docs/document.edit.html | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 docs-web/src/main/webapp/src/partial/docs/directive.selectionrelation.typeahead.html diff --git a/docs-web/src/main/webapp/src/app/docs/directive/SelectRelation.js b/docs-web/src/main/webapp/src/app/docs/directive/SelectRelation.js index bdbd3ee4..33cbe9b7 100644 --- a/docs-web/src/main/webapp/src/app/docs/directive/SelectRelation.js +++ b/docs-web/src/main/webapp/src/app/docs/directive/SelectRelation.js @@ -9,6 +9,7 @@ angular.module('docs').directive('selectRelation', function() { templateUrl: 'partial/docs/directive.selectrelation.html', replace: true, scope: { + id: '=', relations: '=', ref: '@', ngDisabled: '=' @@ -18,21 +19,12 @@ angular.module('docs').directive('selectRelation', function() { * Add a relation. */ $scope.addRelation = function($item) { - // Does the new relation is already in the model - var duplicate = _.find($scope.relations, function(relation) { - if ($item.id === relation.id) { - return relation; - } - }); - // Add the new relation - if (!duplicate) { - $scope.relations.push({ - id: $item.id, - title: $item.title, - source: true - }); - } + $scope.relations.push({ + id: $item.id, + title: $item.title, + source: true + }); $scope.input = ''; }; @@ -42,11 +34,11 @@ angular.module('docs').directive('selectRelation', function() { $scope.deleteRelation = function(deleteRelation) { $scope.relations = _.reject($scope.relations, function(relation) { return relation.id === deleteRelation.id; - }) + }); }; /** - * Returns a promise for typeahead title. + * Returns a promise for typeahead document. */ $scope.getDocumentTypeahead = function($viewValue) { var deferred = $q.defer(); @@ -57,8 +49,16 @@ angular.module('docs').directive('selectRelation', function() { asc: true, search: $viewValue }).then(function(data) { - deferred.resolve(data.documents); - }); + deferred.resolve(_.reject(data.documents, function(document) { + var duplicate = _.find($scope.relations, function(relation) { + if (document.id === relation.id) { + return relation; + } + }); + + return document.id === $scope.id || duplicate; + })); + }); return deferred.promise; }; }, diff --git a/docs-web/src/main/webapp/src/partial/docs/directive.selectionrelation.typeahead.html b/docs-web/src/main/webapp/src/partial/docs/directive.selectionrelation.typeahead.html new file mode 100644 index 00000000..51ab4b31 --- /dev/null +++ b/docs-web/src/main/webapp/src/partial/docs/directive.selectionrelation.typeahead.html @@ -0,0 +1,4 @@ + +
+
{{ match.label.create_date | date: $root.dateFormat }}
+
\ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html b/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html index a5651dc3..c0a00d05 100644 --- a/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html +++ b/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html @@ -7,6 +7,7 @@ \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/document.edit.html b/docs-web/src/main/webapp/src/partial/docs/document.edit.html index da7e7cb9..7301605e 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.edit.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.edit.html @@ -191,7 +191,7 @@
- +