mirror of
https://github.com/sismics/docs.git
synced 2024-11-25 15:17:57 +01:00
Closes #350: better relations widget
This commit is contained in:
parent
8a85830bd3
commit
3b5c27096b
@ -9,6 +9,7 @@ angular.module('docs').directive('selectRelation', function() {
|
|||||||
templateUrl: 'partial/docs/directive.selectrelation.html',
|
templateUrl: 'partial/docs/directive.selectrelation.html',
|
||||||
replace: true,
|
replace: true,
|
||||||
scope: {
|
scope: {
|
||||||
|
id: '=',
|
||||||
relations: '=',
|
relations: '=',
|
||||||
ref: '@',
|
ref: '@',
|
||||||
ngDisabled: '='
|
ngDisabled: '='
|
||||||
@ -18,21 +19,12 @@ angular.module('docs').directive('selectRelation', function() {
|
|||||||
* Add a relation.
|
* Add a relation.
|
||||||
*/
|
*/
|
||||||
$scope.addRelation = function($item) {
|
$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
|
// Add the new relation
|
||||||
if (!duplicate) {
|
$scope.relations.push({
|
||||||
$scope.relations.push({
|
id: $item.id,
|
||||||
id: $item.id,
|
title: $item.title,
|
||||||
title: $item.title,
|
source: true
|
||||||
source: true
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
$scope.input = '';
|
$scope.input = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,11 +34,11 @@ angular.module('docs').directive('selectRelation', function() {
|
|||||||
$scope.deleteRelation = function(deleteRelation) {
|
$scope.deleteRelation = function(deleteRelation) {
|
||||||
$scope.relations = _.reject($scope.relations, function(relation) {
|
$scope.relations = _.reject($scope.relations, function(relation) {
|
||||||
return relation.id === deleteRelation.id;
|
return relation.id === deleteRelation.id;
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a promise for typeahead title.
|
* Returns a promise for typeahead document.
|
||||||
*/
|
*/
|
||||||
$scope.getDocumentTypeahead = function($viewValue) {
|
$scope.getDocumentTypeahead = function($viewValue) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
@ -57,8 +49,16 @@ angular.module('docs').directive('selectRelation', function() {
|
|||||||
asc: true,
|
asc: true,
|
||||||
search: $viewValue
|
search: $viewValue
|
||||||
}).then(function(data) {
|
}).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;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
<a>
|
||||||
|
<div ng-bind-html="match.label.title | uibTypeaheadHighlight: query"></div>
|
||||||
|
<div class="small">{{ match.label.create_date | date: $root.dateFormat }}</div>
|
||||||
|
</a>
|
@ -7,6 +7,7 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<input class="form-control" type="text" id="{{ ref }}" ng-attr-placeholder="{{ 'directive.selectrelation.typeahead' | translate }}" ng-model="input" ng-disabled="ngDisabled"
|
<input class="form-control" type="text" id="{{ ref }}" ng-attr-placeholder="{{ 'directive.selectrelation.typeahead' | translate }}" ng-model="input" ng-disabled="ngDisabled"
|
||||||
autocomplete="off" uib-typeahead="document.title for document in getDocumentTypeahead($viewValue)"
|
autocomplete="off" uib-typeahead="document for document in getDocumentTypeahead($viewValue)"
|
||||||
|
typeahead-template-url="partial/docs/directive.selectionrelation.typeahead.html"
|
||||||
typeahead-wait-ms="200" typeahead-on-select="addRelation($item)" />
|
typeahead-wait-ms="200" typeahead-on-select="addRelation($item)" />
|
||||||
</div>
|
</div>
|
@ -191,7 +191,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-2 control-label" for="inputRelations">{{ 'document.relations' | translate }}</label>
|
<label class="col-sm-2 control-label" for="inputRelations">{{ 'document.relations' | translate }}</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<select-relation relations="document.relations" ref="inputRelations" ng-disabled="fileIsUploading"></select-relation>
|
<select-relation id="document.id" relations="document.relations" ref="inputRelations" ng-disabled="fileIsUploading"></select-relation>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user