Skip to content

Commit

Permalink
Merge branch 'master' into dja-replace-location-svc
Browse files Browse the repository at this point in the history
  • Loading branch information
trepagnier committed Dec 6, 2018
2 parents 2220a26 + 1065461 commit 788b88f
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions app/layers/addLayerDirective.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function addLayers(layerSvc) {
function addLayers(layerSvc, stateSvc) {
return {
restrict: "E",
scope: {
Expand All @@ -7,21 +7,41 @@ function addLayers(layerSvc) {
templateUrl: "./app/layers/templates/add-layers.html",
link: scope => {
let searchObjects;
let titles;

scope.getResults = searchValue =>
scope.getResults = (searchValue) =>
layerSvc.getSearchBarResultsIndex(searchValue).then(data => {
searchObjects = data;
titles = layerSvc.compileLayerTitlesFromSearchIndex(data);
return titles;
let searchLayerArray = [];
const configLayerArray = [];
const searchLayers = layerSvc.compileLayerTitlesFromSearchIndex(data);
const configLayers = stateSvc.config.chapters[stateSvc.getChapterIndex()].layers;

for (let x = 0; x < configLayers.length; x++) {
configLayerArray.push(configLayers[x].title);
}
for (let x = 0; x < searchLayers.length; x++) {
searchLayerArray.push(searchLayers[x]);
}
for (let x = 0; x < configLayerArray.length; x++) {
searchLayerArray = searchLayerArray.filter(item => item !== configLayerArray[x]);
}


if(searchLayerArray.length < 1) {
const errorDiv = document.getElementById("noResults");
errorDiv.innerHTML = "<i class='glyphicon glyphicon-exclamation-sign'> </i> You have added all available layers.";
} else {
return searchLayerArray;
}
return 0;
});

scope.addLayerFromSearchResults = (layerName) => {
const errorDiv = document.getElementById("noResults");
const errorMsg = "<i class=\"glyphicon glyphicon-remove\"></i> No matching layers found.";
const errorMsg = "<i class='glyphicon glyphicon-remove'> </i> No matching layers found.";

if (searchObjects !== undefined && searchObjects.length !== 0) {
for (let x=0; x<searchObjects.length; x++) {
for (let x = 0; x < searchObjects.length; x++) {
if (searchObjects[x].title === layerName) {
errorDiv.innerHTML = "";
layerSvc.addLayerFromApiResults({
Expand Down

0 comments on commit 788b88f

Please sign in to comment.