Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Catalogtree #126

Merged
merged 57 commits into from
Aug 16, 2013
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d299aac
first test with a catalogtree
procrastinatio Jul 3, 2013
d2c6b8b
using a local file to configure the catalog
procrastinatio Jul 12, 2013
c43833a
Fixing rebasing glitches
Jul 17, 2013
7f4eac8
Using templateCache for html snippets (non-working)
Jul 17, 2013
56e2fdf
Working with partials, avoid infite loops
Jul 17, 2013
ab34f4f
Adding sample data with 400 entries to test performance
Jul 17, 2013
a54e00f
Adding tests to update Catalogtree on demand
Jul 17, 2013
726fb48
Adding catalog tree to accordion
Jul 17, 2013
d5fa6a9
Adding more tests, still in recursive hell
Jul 18, 2013
f73062c
Change example to bigger trees
Jul 18, 2013
e723ab8
Fixing the recursive bug...bad code
Jul 18, 2013
8352d61
Using slightly different approach in directive. All in one template w…
Jul 19, 2013
1b006a8
Removing unneeded injections
Jul 19, 2013
21db4e6
Adding example to show usage without root node
Jul 19, 2013
63846ba
Replace ng-if with ng-switch in template
Jul 19, 2013
5bba3b1
Set pulldown max-height
fredj Jul 23, 2013
060b834
Toggle catalog tree using css
fredj Jul 23, 2013
3bf3627
Use checkbox for ga-catalogtree-leaf
fredj Jul 23, 2013
45885ce
Remove list-style icons
fredj Jul 23, 2013
2429a08
Added some additional css styling
Jul 24, 2013
651b5a2
Fix tree toggle
fredj Jul 24, 2013
72d54d3
Getting catalogtree from catalog Service of our API
Jul 24, 2013
0a16d3f
Working now with topic chooser
Jul 24, 2013
5b243fa
Adding ech layers hardcoded for testing
Jul 25, 2013
7f9976c
Simplify switch statement
Jul 25, 2013
ce5a035
Removing unneeded reference to
Jul 25, 2013
a2641fb
You can now add and remove layers from catalog tree
Jul 25, 2013
71ec87c
Specifying comment in more detail
Jul 25, 2013
ed3c5f4
Adding layerId to olLayer to re-use for removal. Now it works on prod
Jul 25, 2013
595cf8f
A little cleanup of the cheat
Jul 25, 2013
938cf42
Getting rid of dirty hack to access map
Jul 26, 2013
d986228
Some renamings to conform better to our conventions
Jul 26, 2013
eebf2f5
Fix examples to keep up with latest changes. Now contains a map
Jul 26, 2013
1a5b569
Add some styling to bring the catalog closer to the specs
Jul 30, 2013
1cda445
Fix typon in error message
Jul 30, 2013
b3d8ece
Removing unneeded code
Jul 30, 2013
f9d1c7d
Remove temporary fix
Jul 30, 2013
a7eb6d4
React to language changes in Catalogtree
Jul 30, 2013
76faeb6
Fix idents
Jul 30, 2013
4409649
Refine error message
Jul 30, 2013
339ff1a
Adding preview of layer on hover (inspired by oteral)
Jul 30, 2013
97c2b2a
Fix build
Jul 30, 2013
5213d37
Adding a little sugar to onhover and other things
Jul 31, 2013
8e2b368
Adding Font Awsome icons for checkbox
Aug 8, 2013
fc76b19
Adding service to get metadata and link it
Aug 8, 2013
b813229
Some refactorings to increase readability. Minor changes
Aug 9, 2013
230583a
Make directive workable after rebase to master
Aug 13, 2013
a45aac4
Adapt styling and html structure, fix chrome/MAC bug
Aug 15, 2013
504c4a9
Adding popup for metadata/legend info window
Aug 15, 2013
a617b73
Renaming of files to prepare for container directive
Aug 16, 2013
29ff945
Renaming of elements
Aug 16, 2013
8b0b860
Adding new wrapper directive for catalogtree
Aug 16, 2013
a4ff512
Take out responsibility to update tree from controller and put it int…
Aug 16, 2013
3a87edd
Make example work with latest changes
Aug 16, 2013
d750ab8
Fix naming and ident
Aug 16, 2013
4ed9129
Remove update function from scope
Aug 16, 2013
ca0ae2a
Taking into account recent comments
Aug 16, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rc_ltmom
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
source rc_dev

export BASE_URL_PATH=/ltmom
export SERVICE_URL=http://mf-chsdi30t.bgdi.admin.ch

139 changes: 139 additions & 0 deletions src/components/catalogtree/CatalogitemDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
(function() {
goog.provide('ga_catalogitem_directive');

goog.require('ga_map_service');
goog.require('ga_popup_service');

//static functions
function getMapLayer(map, id) {
var layer;
map.getLayers().forEach(function(l) {
if (l.get('id') == id) {
layer = l;
}
});
return layer;
};

function addLayerToMap(scope, doAlert) {
var layer = getMapLayer(scope.map, scope.item.idBod),
olLayer;
if (!angular.isDefined(layer)) {
olLayer = scope.gaLayers.getOlLayerById(scope.item.idBod);
if (olLayer) {
scope.item.errorLoading = false;
scope.map.getLayers().push(olLayer);
} else {
if (doAlert) {
//FIXME: better error handling
var msg = 'The desired Layer is not defined ' +
'by the gaLayers service (' + scope.item.idBod + ').';
alert(msg);
}
scope.item.errorLoading = true;
scope.item.selectedOpen = false;
}
}
};

function removeLayerFromMap(map, id) {
var layer = getMapLayer(map, id);
if (angular.isDefined(layer)) {
map.removeLayer(layer);
}
};

var module = angular.module('ga_catalogitem_directive', [
'ga_map_service',
'ga_popup_service'
]);

/**
* See examples on how it can be used
*/
module.directive('gaCatalogitem',
['$compile', 'gaLayers', 'gaPopup',
function($compile, gaLayers, gaPopup) {
return {
restrict: 'A',
templateUrl: 'components/catalogtree/partials/catalogitem.html',
scope: {
item: '=gaCatalogitemItem',
map: '=gaCatalogitemMap'
},
compile: function(tEl, tAttr) {
var contents = tEl.contents().remove();
var compiledContent;
return function(scope, iEl, iAttr) {
if (!compiledContent) {
compiledContent = $compile(contents);
}
scope.gaLayers = gaLayers;
scope.getLegend = getLegend;
scope.toggle = toggle;
scope.switchLayer = switchLayer;
scope.previewLayer = previewLayer;
scope.removePreviewLayer = removePreviewLayer;

compiledContent(scope, function(clone, scope) {
iEl.append(clone);
});
};
}
};
function previewLayer() {
if (this.map) {
if (this.item.selectedOpen) {
removeLayerFromMap(this.map, this.item.idBod);
} else {
addLayerToMap(this, false);
}
this.item.preview = true;
}
};

function removePreviewLayer() {
this.switchLayer(false);
this.item.preview = false;
};

function switchLayer(fromClick) {
if (fromClick) {
this.item.selectedOpen = !this.item.selectedOpen;
}
if (this.map) {
if (this.item.selectedOpen) {
addLayerToMap(this, fromClick);
} else {
removeLayerFromMap(this.map, this.item.idBod);
}
}
};

function toggle(ev) {
this.item.selectedOpen = !this.item.selectedOpen;
ev.preventDefault();
};

function getLegend(ev, bodid) {
var scope = this;
scope.gaLayers.getMetaDataOfLayer(bodid)
.success(function(data) {
gaPopup.create({
title: 'metadata_window_title',
content: data,
x: 400,
y: 200
}).open(scope);
})
.error(function() {
//FIXME: better error handling
var msg = 'Could not retrieve information for ' + bodid;
alert(msg);
});
ev.stopPropagation();
};
}]
);
})();

53 changes: 53 additions & 0 deletions src/components/catalogtree/CatalogtreeDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(function() {
goog.provide('ga_catalogtree_directive');

var module = angular.module('ga_catalogtree_directive', [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your module should depend on ga_translation.

]);

/**
* See examples on how it can be used
*/
module.directive('gaCatalogtree',
['$http', '$translate',
function($http, $translate) {
return {
restrict: 'A',
replace: true,
templateUrl: 'components/catalogtree/partials/catalogtree.html',
scope: {
options: '=gaCatalogtreeOptions',
map: '=gaCatalogtreeMap'
},
link: function(scope, element, attrs) {
var currentTopic;
scope.updateCatalogTree = function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a reference to the updateCatalogTree function in the scope? Instead, can't updateCatalogTree just be local to the link function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. I'll adapt.

if (angular.isDefined(currentTopic)) {
$http.jsonp(scope.options.getUrlForTopic(currentTopic), {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used a URL template rather than a URL function in #261. We should be consistent. I have a preference for templates but I can probably be convinced otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no problem going the template way. But the change would be in the controller, not the directive, right? So we would still have a function call to the controller function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I saw it the directive would do

var url = scope.options.catalogUrlTemplate.replace('{Topic}', currentTopic);

params: {
'lang': $translate.uses(),
'callback': 'JSON_CALLBACK'
}
}).success(function(data, status, header, config) {
scope.root = data.results.root;
}).error(function(data, status, headers, config) {
scope.root = undefined;
});
}
};

scope.$on('translationChangeSuccess', function() {
scope.updateCatalogTree();
});

scope.$on('gaTopicChange', function(event, topic) {
currentTopic = topic.id;
scope.updateCatalogTree();
});


}
};
}]
);
})();

11 changes: 11 additions & 0 deletions src/components/catalogtree/CatalogtreeModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function() {
goog.provide('ga_catalogtree');

goog.require('ga_catalogitem_directive');
goog.require('ga_catalogtree_directive');

angular.module('ga_catalogtree', [
'ga_catalogitem_directive',
'ga_catalogtree_directive'
]);
})();
Loading