Skip to content
Permalink
Browse files

Componet for storing/displaying history of wms'es

This will be a dropdown list which can be
appended to input elements input-group-append element
fixes #231
  • Loading branch information...
raitisbe committed Jul 21, 2019
1 parent da20b2e commit 689e5497745b19fc5b90064781d7360f768daf5f
@@ -0,0 +1,8 @@
<button type="button" ng-click="historyDropdownVisible=!historyDropdownVisible"
class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
<div class="dropdown-menu" style="left: auto; right:0; width:325px; overflow: hidden" ng-class="{'show': historyDropdownVisible}">
<a class="dropdown-item" ng-repeat="item in items" ng-click="clicked(item)" href="#">{{item}}</a>
</div>
</button>
@@ -0,0 +1,15 @@
export default ['config', function (config) {
return {
template: require('common/history-list/history-list.directive.html'),
scope: {
what: '@what',
clicked: '=clicked'
},
replace: true,
transclude: true,
controller: ['$scope', 'hs.historyListService', function($scope, historyListService){
$scope.items = historyListService.readSourceHistory($scope.what);
}]

};
}]
@@ -0,0 +1,19 @@
import historyListDirective from "./history-list.directive";
import historyListService from "./history-list.service";

export default angular.module('hs.historyList', ['ngCookies'])
/**
* @memberof hs.addLayers
* @ngdoc directive
* @name compile
* @description Directive which displays list of previously used urls or any other string
*/
.directive('hs.historyList', historyListDirective)

/**
* @memberof hs.addLayers
* @ngdoc service
* @name compile
* @description Service which reads and writes list of previously used urls or any other string
*/
.service('hs.historyListService', historyListService)
@@ -0,0 +1,35 @@
export default ['$cookies', function ($cookies) {
var me = this;
/**
* items is a dictionary/cache of various history lists.
* It is populated from history.directive by readSourceHistory function
* and then appended by addSourceHistory function
*/
me.items = {};

me.readSourceHistory = function (forWhat) {
var sourceString = $cookies.get(`last${forWhat}Sources`);
if (angular.isDefined(sourceString)) {
me.items[forWhat] = uniq(JSON.parse(sourceString));
} else {
me.items[forWhat] = [];
}
return me.items[forWhat]
}

function uniq(a) {
return a.sort().filter(function (item, pos, ary) {
return !pos || item != ary[pos - 1];
})
}

me.addSourceHistory = function (forWhat, url) {
if (angular.isUndefined(me.items[forWhat])) me.items[forWhat] = [];
if (me.items[forWhat].indexOf(url) == -1) {
me.items[forWhat].push(url);
$cookies.put(`last${forWhat}Sources`, JSON.stringify(me.items[forWhat]));
}
}

return me;
}]

0 comments on commit 689e549

Please sign in to comment.
You can’t perform that action at this time.