mirror of
https://github.com/nasa/openmct.git
synced 2025-02-21 01:42:31 +00:00
[Search] Framework of webworker implementation
Made a basic outline of the desired web worker implementation. (Functions present, now need to implement them.)
This commit is contained in:
parent
74961e1106
commit
c1dcd8ea5b
@ -46,10 +46,10 @@ define(
|
||||
function GenericSearchProvider($rootScope, objectService, workerService) {
|
||||
var validType = function () {return true;};
|
||||
|
||||
/*
|
||||
var worker = workerService.run('genericSearchWorker'),
|
||||
lastestItems;
|
||||
|
||||
/*
|
||||
function requestItems() {
|
||||
// Aquire My Items (root folder)
|
||||
// I don't think we can do this part in the webworker because of the objectService
|
||||
@ -81,9 +81,33 @@ define(
|
||||
}
|
||||
*/
|
||||
|
||||
// Tell the web worker to add a new item's model to its list of items.
|
||||
function indexItem(domainObject) {
|
||||
var message = {
|
||||
request: 'index',
|
||||
model: domainObject.getModel()
|
||||
};
|
||||
// Note that getModel() by definition returns a JavaScript object
|
||||
// that can be losslesly converted to a JSON object.
|
||||
worker.postMessage(message);
|
||||
}
|
||||
|
||||
// Tell the worker to search for items it has that match this searchInput.
|
||||
// Takes the searchInput, as well as a max number of results (will return
|
||||
// less than that if there are fewer matches).
|
||||
function workerSearch(searchInput, numberOfResults) {
|
||||
var message = {
|
||||
request: 'search',
|
||||
input: searchInput,
|
||||
number: numberOfResults
|
||||
};
|
||||
worker.postMessage(message);
|
||||
}
|
||||
|
||||
function handleResponse(event) {
|
||||
latest = event.data;
|
||||
$rootScope.$apply();
|
||||
//latest = event.data;
|
||||
//console.log('handleResponse', event.data);
|
||||
//$rootScope.$apply();
|
||||
//requestNext();
|
||||
}
|
||||
|
||||
|
47
platform/features/search/src/workers/GenericSearchWorker.js
Normal file
47
platform/features/search/src/workers/GenericSearchWorker.js
Normal file
@ -0,0 +1,47 @@
|
||||
/*****************************************************************************
|
||||
* 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 self*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var indexedItems = [];
|
||||
|
||||
function index(data) {
|
||||
// Takes an object model
|
||||
// Add to indexedItems
|
||||
}
|
||||
|
||||
function search(data) {
|
||||
// Takes a search input and the number of items to find
|
||||
// Converts it into search terms
|
||||
// Gets matches from indexedItems
|
||||
}
|
||||
|
||||
self.onmessage = function (event) {
|
||||
if (event.data.request === 'index') {
|
||||
self.postMessage(index(event.data));
|
||||
} else if (event.data.request === 'search') {
|
||||
self.postMessage(search(event.data));
|
||||
}
|
||||
};
|
||||
}());
|
Loading…
x
Reference in New Issue
Block a user