[Search] Renaming and adding files

Renamed QueryService as SearchService and changed
the corresponding references to it. Added a
SearchAggregator file and related files. Not
yet begun with the implementation.
This commit is contained in:
shale 2015-07-16 10:10:07 -07:00
parent 1e05ebbfd7
commit 6f2ad0dadc
9 changed files with 107 additions and 14 deletions

View File

@ -28,11 +28,11 @@
>
<mct-representation key="'create-button'" mct-object="navigatedObject">
</mct-representation>
<div>
<!-- div>
<mct-include key="'searchbar'"
mct-object="domainObject">
</mct-include>
</div>
</div -->
<div class='holder tree-holder abs'>
<mct-representation key="'tree'"
mct-object="domainObject"

View File

@ -14,13 +14,13 @@
"controllers": [
{
"key": "SearchController",
"implementation": "SearchController.js",
"depends": [ "$scope", "queryService" ]
"implementation": "controllers/SearchController.js",
"depends": [ "$scope", "searchService" ]
},
{
"key": "SearchbarController",
"implementation": "SearchbarController.js",
"depends": [ "$scope", "queryService" ]
"implementation": "controllers/SearchbarController.js",
"depends": [ "$scope", "searchService" ]
}
],
"templates": [
@ -39,8 +39,8 @@
],
"services": [
{
"key": "queryService",
"implementation": "QueryService.js",
"key": "searchService",
"implementation": "SearchService.js",
"depends": [ "$http", "objectService", "ELASTIC_ROOT" ]
}
]

View File

@ -0,0 +1,93 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is 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.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define*/
/**
* Module defining ModelAggregator. Created by vwoeltje on 11/7/14.
*/
define(
[],
function () {
"use strict";
/**
* Allows multiple services which provide models for domain objects
* to be treated as one.
*
* @constructor
* @param {ModelProvider[]} providers the model providers to be
* aggregated
*/
function ModelAggregator($q, providers) {
// Pick a domain object model to use, favoring the one
// with the most recent timestamp
function pick(a, b) {
var aModified = (a || {}).modified || Number.NEGATIVE_INFINITY,
bModified = (b || {}).modified || Number.NEGATIVE_INFINITY;
return (aModified > bModified) ? a : (b || a);
}
// Merge results from multiple providers into one
// large result object.
function mergeModels(provided, ids) {
var result = {};
ids.forEach(function (id) {
provided.forEach(function (models) {
if (models[id]) {
result[id] = pick(result[id], models[id]);
}
});
});
return result;
}
return {
/**
* Get models with the specified identifiers.
*
* This will invoke the `getModels()` method of all providers
* given at constructor-time, and aggregate the result into
* one object.
*
* Note that the returned object may contain a subset or a
* superset of the models requested.
*
* @param {string[]} ids an array of domain object identifiers
* @returns {Promise.<object>} a promise for an object
* containing key-value pairs,
* where keys are object identifiers and values
* are object models.
*/
getModels: function (ids) {
return $q.all(providers.map(function (provider) {
return provider.getModels(ids);
})).then(function (provided) {
return mergeModels(provided, ids);
});
}
};
}
return ModelAggregator;
}
);

View File

@ -43,7 +43,7 @@ define(
* elasticsearch).
* @constructor
*/
function QueryService($http, objectService, ROOT) {
function SearchService($http, objectService, ROOT) {
var DEFAULT_MAX_RESULTS = 100;
/////////////// The following is for non-Elastic Search /////////////////
@ -286,6 +286,6 @@ define(
};
}
return QueryService;
return SearchService;
}
);

View File

@ -27,12 +27,12 @@
define(function () {
"use strict";
function SearchController($scope, queryService) {
function SearchController($scope, searchService) {
return {
// Search the database using the user input of id "searchinput"
search: function (inputID) {
queryService.query(inputID).then(function (c) {
searchService.query(inputID).then(function (c) {
$scope.results = c;
});
},

View File

@ -27,12 +27,12 @@
define(function () {
"use strict";
function SearchbarController($scope, queryService) {
function SearchbarController($scope, searchService) {
return {
// Search the database using the user input of id "searchinput"
search: function (inputID) {
queryService.query(inputID).then(function (c) {
searchService.query(inputID).then(function (c) {
$scope.results = c;
});
},