harbor/static/ng/resources/js/components/search/search.directive.js
2016-05-14 13:34:54 +08:00

52 lines
1.1 KiB
JavaScript

(function() {
'use strict';
angular
.module('harbor.search')
.directive('search', search);
SearchController.$inject = ['SearchService', '$scope'];
function SearchController(SearchService, $scope) {
var vm = this;
vm.keywords = "";
vm.search = searchByFilter;
vm.filterBy = 'repository';
searchByFilter();
function searchByFilter() {
SearchService(vm.keywords)
.success(searchSuccess)
.error(searchFailed);
}
function searchSuccess(data, status) {
console.log('filterBy:' + vm.filterBy + ", data:" + data);
vm.searchResult = data[vm.filterBy];
}
function searchFailed(data, status) {
console.log('Failed search:' + data);
}
}
function search() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/ng/resources/js/components/search/search.directive.html',
'scope': {
'filterBy': '='
},
'controller': SearchController,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
}
})();