[Search] Listify filetree

SearchController now attempts to convert the filetree
into a list format. Still needs to be modified to be
asynchronous.
This commit is contained in:
shale 2015-07-09 11:16:55 -07:00
parent 32eaf3893a
commit 94b306e129
4 changed files with 92 additions and 16 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "Search View", "name": "Search View",
"description": "Allows the user to search through the file three.", "description": "Allows the user to search through the file tree.",
"extensions": { "extensions": {
"views": [ "views": [
{ {
@ -15,14 +15,14 @@
{ {
"key": "SearchController", "key": "SearchController",
"implementation": "SearchController.js", "implementation": "SearchController.js",
"depends": [ "$scope" ] "depends": [ "$scope", "objectService" ]
} }
], ],
"representations": [ "representations": [
{ {
"key": "search-item", "key": "search-item",
"templateUrl": "templates/search-item.html", "templateUrl": "templates/search-item.html",
"uses": [ "type", "action" ], "uses": [ "type", "action", "composition" ],
"gestures": [ "info", "menu" ] "gestures": [ "info", "menu" ]
} }
] ]

View File

@ -23,7 +23,7 @@
<!-- For selected, add class 'selected' to outer div --> <!-- For selected, add class 'selected' to outer div -->
<div class='item' ng-click='action.perform("navigate")'> <div class='item' ng-click='action.perform("navigate")'>
ITEM ITEM
<div class="contents abs"> <!--div class="contents abs">
<div class='top-bar bar abs'> <div class='top-bar bar abs'>
<div class='left abs'> <div class='left abs'>
<mct-include key="_checkbox"></mct-include> <mct-include key="_checkbox"></mct-include>
@ -45,5 +45,5 @@
</span> </span>
</div> </div>
</div> </div>
</div> </div-->
</div> </div>

View File

@ -20,14 +20,23 @@
at runtime from the About dialog for additional information. at runtime from the About dialog for additional information.
--> -->
<!-- Based on items --> <!-- Based on items -->
<div class='items-holder grid abs'> <div class="items-holder grid abs"
ng-controller="SearchController as controller">
<!-- Search bar --> <!-- Search bar -->
<div> <div id="formid">
<form> <form>
<div>
<label for="searchinput">Search this folder:</label>
<input type="text" id="searchinput" />
</div>
<!--
Search in this folder: <br> Search in this folder: <br>
<input type="text" name="searchform"> <input type="text" name="searchform"> -->
<input type="submit" value="Search"> <div class="button">
<button type="submit">Search</button>
</div>
<!-- input type="submit" value="Search" -->
</form> </form>
</div> </div>
@ -42,7 +51,9 @@
mct-object="childObject"--></mct-representation> mct-object="childObject"--></mct-representation>
</li> </li>
<li> <li>
<mct-representation key="'search-item'"></mct-representation> <mct-representation key="'search-item'"
ng-repeat="result in results"
mct-object="result"></mct-representation>
</li> </li>
</ul> </ul>

View File

@ -19,30 +19,95 @@
* this source code distribution or the Licensing information page available * this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/*global define,Promise*/ /*global define*/
/** /**
* Module defining SearchController. Created by shale on 07/08/2015. * Module defining SearchController. Created by shale on 07/08/2015.
*/ */
define(function () { define(function () {
"use strict";
function SearchController($scope) { function SearchController($scope, objectService) {
var items = [], var items = [],
searchResults = []; searchResults = [];
// Indexes the filetree into a searchable format // Get the root object
function indexTree() { /*
objectService.getObjects(['root']).then(function (objects) {
console.log('rootObject 1', rootObject);
rootObject = objects.root;
console.log('rootObject 2', rootObject);
console.log('hasCapability("editor") ', rootObject.hasCapability('editor'));
console.log('getModel() ', rootObject.getModel());
console.log('getId() ', rootObject.getId());
// Get the children of the root object
console.log('hasCapability("composition") ', rootObject.hasCapability('composition'));
if (rootObject.hasCapability('composition')) {
rootComposition = rootObject.getCapability('composition').invoke();
console.log('rootComposition ', rootComposition);
}
});
console.log('rootObject 3', rootObject);
*/
// Converts the filetree into a list
// Eventually, plan to call search service
// (but do here for now)
function listify() {
// For now, we want this view to only be in the My Items folder
if ($scope.domainObject.getId() === 'mine') {
var out = listHelper($scope.domainObject);
//console.log('out', out);
return out;
}
// Fallback if we aren't in My Items
return items;
}
// Recursive helper function to go through the tree
function listHelper(current) {
//console.log('current', current);
//console.log('current.getID', current.getId());
var composition;
if (current.hasCapability('composition')) {
composition = current.getCapability('composition');
} else {
//console.log('does not have capability');
return current;
}
composition.invoke().then(function (children) {
if (children === []) {
return current;
} else {
var subList = [current],
i;
for (i = 0; i < children.length; i += 1) {
subList.concat(listHelper(children[i]));
}
//console.log('subList ', subList); ////////////
return subList;
}
});
} }
// Search through items for items which have the search term // Search through items for items which have the search term
// in the title // in the title
function search(term) { function search(term) {
// modify searchResults // modify searchResults
return searchResults;
} }
// When the search view is opened, call indexTree() // When the search view is opened, call listify()
// When the search button is pressed, call search() // When the search button is pressed, call search()
$scope.items = listify();
$scope.results = search();
} }
return SearchController; return SearchController;
}); });