diff --git a/src/app/search/controller/search_controller.js b/src/app/search/controller/search_controller.js
new file mode 100644
index 00000000..e75ad1e8
--- /dev/null
+++ b/src/app/search/controller/search_controller.js
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * This controller provides initialization logic for the generic search view.
+ */
+angular.module('sb.search').controller('SearchController',
+ function ($log, $q, $scope, Criteria, $stateParams) {
+ 'use strict';
+
+ /**
+ * Default criteria, potentially populated by the q param.
+ *
+ * @type {Array}
+ */
+ $scope.defaultCriteria = [];
+
+ /**
+ * List of resource types which this view will be searching on.
+ *
+ * @type {string[]}
+ */
+ $scope.resourceTypes = ['Story', 'Project', 'User', 'Task'];
+
+ /**
+ * If a 'q' exists in the state params, go ahead and add it.
+ */
+ if ($stateParams.hasOwnProperty('q') && !!$stateParams.q) {
+ $scope.defaultCriteria.push(
+ Criteria.create('Text', $stateParams.q)
+ );
+ }
+ }
+);
diff --git a/src/app/search/controller/search_criteria_controller.js b/src/app/search/controller/search_criteria_controller.js
index f8be8f20..a3329c28 100644
--- a/src/app/search/controller/search_criteria_controller.js
+++ b/src/app/search/controller/search_criteria_controller.js
@@ -16,18 +16,19 @@
/**
* The sole purpose of this controller is to allow a user to search for valid
- * search/filter criteria, and expose chosen criteria to the scope. These
- * criteria may either be resources, resource identifiers (type/id pairs),
- * or plain strings.
+ * search/filter criteria for various resources, and expose chosen criteria
+ * to the scope. These criteria may be static or asynchronously loaded, and
+ * may be property filters (title = foo) or resource filters (story_id = 22).
*/
angular.module('sb.search').controller('SearchCriteriaController',
- function ($log, $q, $scope, Criteria, Browse, $stateParams) {
+ function ($log, $q, $scope, Criteria) {
'use strict';
/**
- * Valid sets of resources that can be searched on.
+ * Valid sets of resources that can be searched on. The default
+ * assumes no resources may be searched.
*/
- var resourceTypes = ['Story', 'Project', 'User', 'Task'];
+ var resourceTypes = [];
/**
* Managed list of active criteria tags.
@@ -37,32 +38,34 @@ angular.module('sb.search').controller('SearchCriteriaController',
$scope.criteria = [];
/**
- * When a criteria is added, make sure we remove duplicates - the
- * control doesn't handle that for us.
+ * Initialize this controller with different resource types and
+ * default search criteria.
+ *
+ * @param types
+ * @param defaultCriteria
+ */
+ $scope.init = function (types, defaultCriteria) {
+ resourceTypes = types || resourceTypes;
+ $scope.criteria = defaultCriteria || [];
+ $scope.searchForCriteria =
+ Criteria.buildCriteriaSearch(resourceTypes);
+ };
+
+ /**
+ * When a criteria is added, make sure we remove all previous criteria
+ * that have the same type.
*/
$scope.addCriteria = function (item) {
- var idx = $scope.criteria.indexOf(item);
-
- for (var i = 0; i < $scope.criteria.length; i++) {
+ for (var i = $scope.criteria.length - 1; i >= 0; i--) {
var cItem = $scope.criteria[i];
// Don't remove exact duplicates.
- if (idx === i) {
+ if (cItem === item) {
continue;
}
- // We can only search for one text type at a time.
- if (item.type === 'text' &&
- cItem.type === 'text') {
+ if (item.type === cItem.type) {
$scope.criteria.splice(i, 1);
- break;
- }
-
- // Remove any duplicate value types.
- if (item.type === cItem.type &&
- item.value === cItem.value) {
- $scope.criteria.splice(i, 1);
- break;
}
}
};
@@ -99,30 +102,10 @@ angular.module('sb.search').controller('SearchCriteriaController',
/**
* Search for available search criteria.
*/
- $scope.searchForCriteria = function (searchString) {
+ $scope.searchForCriteria = function () {
var deferred = $q.defer();
-
- searchString = searchString || '';
-
- Browse.all(searchString).then(function (results) {
-
- // Add text.
- results.unshift(Criteria.create('text', searchString));
-
- deferred.resolve(results);
- });
-
- // Return the search promise.
+ deferred.resolve([]);
return deferred.promise;
};
-
- /**
- * If a 'q' exists in the state params, go ahead and add it.
- */
- if ($stateParams.hasOwnProperty('q') && !!$stateParams.q) {
- $scope.criteria.push(
- Criteria.create('text', $stateParams.q)
- );
- }
}
);
diff --git a/src/app/search/module.js b/src/app/search/module.js
index aa824c54..33c0c737 100644
--- a/src/app/search/module.js
+++ b/src/app/search/module.js
@@ -27,6 +27,7 @@ angular.module('sb.search',
$stateProvider
.state('search', {
url: '/search?q',
- templateUrl: 'app/search/template/index.html'
+ templateUrl: 'app/search/template/index.html',
+ controller: 'SearchController'
});
});
diff --git a/src/app/search/template/criteria_tag_item.html b/src/app/search/template/criteria_tag_item.html
new file mode 100644
index 00000000..474a6a0c
--- /dev/null
+++ b/src/app/search/template/criteria_tag_item.html
@@ -0,0 +1,60 @@
+
+
+
+