/
ng-skos.min.js
1 lines (1 loc) · 20.3 KB
/
ng-skos.min.js
1
"use strict";angular.module("ngSKOS",[]).constant("ngSKOS.version","0.0.12"),angular.module("ngSKOS").directive("skosBrowser",function(){return{restrict:"E",scope:{concept:"=concept",scheme:"=conceptScheme"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/skos-browser.html"},link:function(scope){angular.forEach(["URI","Notation","Label"],function(value){var lookup=scope.scheme["lookup"+value];lookup&&(scope["select"+value]=function(query){console.log("skosBrowser.select"+value+": "+query),lookup(query).then(function(response){angular.copy(response,scope.concept)})})}),scope.selectConcept=function(concept){scope.selectURI&&concept.uri?scope.selectURI(concept.uri):scope.selectNotation&&concept.notation&&concept.notation.length?scope.selectNotation(concept.notation):scope.selectLabel&&concept.prefLabel&&scope.selectLabel(concept.prefLabel)}}}}),angular.module("ngSKOS").directive("skosConcept",function(){return{restrict:"AE",scope:{concept:"=skosConcept",language:"=language",click:"=skosClick"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/skos-concept.html"},link:function(scope){scope.isEmptyObject=function(){var keys=Object.keys;return!(keys&&keys.length)},scope.$watch("concept",function(concept){angular.forEach(["altLabel","changeNote","contributor","created","creator","definition","depiction","editorialNote","example","hiddenLabel","historyNote","identifier","issued","modified","notation","partOf","prefLabel","publisher","scopeNote","subjectOf","subject","type","uri","url","broader","narrower","related","previous","next","startDate","endDate","relatedDate","location","ancestors","inScheme","topConceptOf","relatedPlace"],function(field){scope[field]=concept?concept[field]:null})},!0)}}}),angular.module("ngSKOS").directive("skosLabel",function(){return{restrict:"A",scope:{label:"=skosLabel"},template:"{{label[language]}}",link:function(scope,element,attrs){function updateLanguage(language){scope.language=language?language:attrs.lang,language=scope.label?selectLanguage(scope.label,scope.language):"",language!=scope.language&&(scope.language=language),attrs.$set("skos-lang",language)}function selectLanguage(labels,languages){return angular.isObject(labels)?(languages&&-1!==languages.indexOf(",")&&(languages=languages.split(",")),angular.isString(languages)&&angular.isString(labels[languages])?languages:angular.isArray(languages)&&angular.isString(labels[languages[0]])?languages[0]:guessLanguage(labels,languages)):void 0}function guessLanguage(labels,languages){if(languages)if(angular.isString(languages)){for(var dialect in labels)if(0===dialect.toLowerCase().indexOf(languages)||0===languages.toLowerCase().indexOf(dialect))return dialect}else if(angular.isArray(languages))for(var i in languages)for(var dialect in labels)if(0===dialect.toLowerCase().indexOf(languages[i].toLowerCase())||0===languages[i].toLowerCase().indexOf(dialect.toLowerCase()))return dialect;if(!labels.und)return"";for(var language in labels)if("und"==language&&"false"!==labels[language]&&"true"!==labels[language])return language}attrs.$observe("lang",updateLanguage),scope.$watch("label",function(){updateLanguage()},!0)}}}),angular.module("ngSKOS").directive("skosList",["$timeout",function($timeout){return{restrict:"E",scope:{concepts:"=concepts",onSelect:"=onSelect",canRemove:"=removeable",showLabels:"=showLabels",lang:"=language",listname:"@listName"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/skos-list.html"},link:function(scope){scope.$watch("concepts"),scope.$watch("lang",function(lang){scope.popOverTitle=function(label){if(1!=scope.showLabels){if(label[lang])return label[lang];for(lang in label)return label[lang]}}}),scope.removeConcept=function(index){scope.concepts.splice(index,1)},scope.focusConcept=function(index){scope.listname||(scope.listname=Math.random().toString(36).slice(2));var fc=angular.element("[list-index="+scope.listname+"_"+index+"]");fc.focus()},scope.tabFocus=0,scope.onClick=function(index){scope.tabFocus=index,scope.onSelect&&scope.onSelect(scope.concepts[index])},scope.onFocus=function(index){scope.tabFocus=index},scope.onKeyDown=function($event,first,last,index){var key=$event.keyCode,length=scope.concepts.length;-1!=[38,40,46,13].indexOf(key)&&0!=length&&($event.preventDefault(),38==key?(scope.tabFocus=(scope.tabFocus+length-1)%length,$timeout(function(){scope.focusConcept(scope.tabFocus)},0,!1)):40==key?(scope.tabFocus=(scope.tabFocus+1)%length,$timeout(function(){scope.focusConcept(scope.tabFocus)},0,!1)):46==key&&1==scope.canRemove?(last&&scope.tabFocus--,scope.removeConcept(index),$timeout(function(){scope.focusConcept(scope.tabFocus)},0,!1)):13==key&&scope.onSelect&&($event.preventDefault(),scope.onSelect(scope.concepts[index])))}}}}]),angular.module("ngSKOS").directive("skosMappingTable",function(){return{restrict:"A",scope:{mapping:"=skosMappingTable",select:"=selectMapping",lookup:"=lookupMapping",lang:"=language",schemes:"=activeSchemes"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/skos-mapping-table.html"},link:function(scope){scope.$watch("lang",function(lang){scope.popOverTitle=function(label){if(label[lang])return label[lang];for(lang in label)return label[lang]}}),scope.$watch("schemes")},controller:["$scope",function($scope){$scope.predicate="-mappingRelevance"}]}}),angular.module("ngSKOS").directive("skosNotes",function(){return{restrict:"A",scope:{notes:"=skosNotes"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/skos-notes.html"},link:function(scope,element,attrs){function update(language){scope.language=language?language:attrs.lang,language||(language=guessLanguage(scope.notes)),language!=scope.language&&(scope.language=language)}function guessLanguage(notes){for(var type in notes)for(var language in notes[type])return language}attrs.$observe("lang",update),scope.$watch("notes",function(notes){angular.forEach(["scopeNote","definition","example","historyNote"],function(field){scope[field]=angular.isObject(notes)?notes[field]:null})},!0)}}}),angular.module("ngSKOS").directive("skosTree",["$compile",function($compile){return{restrict:"A",transclude:!0,scope:{tree:"=skosTree",language:"=language"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/skos-tree.html"},compile:function(tElement,tAttr,transclude){var compiledContents,contents=tElement.contents().remove();return function(scope,iElement){compiledContents||(compiledContents=$compile(contents,transclude)),compiledContents(scope,function(clone){iElement.append(clone)})}}}}]),angular.module("ngSKOS").factory("SkosConceptSource",["SkosHTTP",function(SkosHTTP){var SkosConceptSource=function(args){SkosHTTP.call(this,args)};return SkosConceptSource.prototype=new SkosHTTP,SkosConceptSource.prototype.getConcept=function(concept){var url;if(this.url)if(angular.isFunction(this.url))url=this.url(concept);else{if(url=this.url,concept.notation){var notation=concept.notation[0];url=url.replace("{notation}",decodeURIComponent(notation))}url=url.replace("{uri}",decodeURIComponent(concept.uri))}else url=concept.uri;return this.get(url)},SkosConceptSource.prototype.updateConcept=function(concept){return this.getConcept(concept).then(function(response){angular.copy(response,concept)})},SkosConceptSource.prototype.updateConnected=function(concept,which){angular.isString(which)?which=[which]:angular.isArray(which)||(which=["broader","narrower","related"]);var service=this;angular.forEach(which,function(w){angular.forEach(concept[w],function(c){service.updateConcept(c)})})},SkosConceptSource}]),angular.module("ngSKOS").factory("SkosHTTP",["$http","$q",function($http,$q){var SkosHTTP=function(args){args||(args={}),this.transform=args.transform,this.url=args.url;var jsonp=args.jsonp;jsonp&&(jsonp===!0||angular.isNumber(jsonp)||jsonp.match(/^\d/))&&(jsonp="callback"),this.jsonp=jsonp};return SkosHTTP.prototype={get:function(url){url||(url=this.url);var transform=this.transform,get=$http.get;return this.jsonp&&(get=$http.jsonp,url+=-1==url.indexOf("?")?"?":"&",url+=this.jsonp+"=JSON_CALLBACK"),get(url).then(function(response){try{return transform?transform(response.data):response.data}catch(e){return console.error(e),$q.reject(e)}},function(response){return console.error(response),$q.reject(response.data)})}},SkosHTTP}]),angular.module("ngSKOS").run(["$templateCache",function($templateCache){$templateCache.put("template/skos-browser.html",'<div ng-if="scheme.suggest" style="margin:1em 0em;position:relative"><input class="form-control" suggest-typeahead="scheme.suggest" typeahead-on-select="selectNotation($item.description)" ng-model="conceptLabel" placeholder="Search by terms (typeahead)" typeahead-loading="loading" typeahead-editable="false"> <span ng-show="loading" class="typeahead-loading-right"><i class="glyphicon glyphicon-refresh"></i></span></div><div ng-if="selectNotation" class="search-top" style="overflow:hidden;margin-bottom:15px"><form ng-submit="selectNotation(notation)"><span style="float:left"><input class="form-control search-top-input" ng-model="notation" placeholder="Enter full notation"></span> <button type="submit" ng-disabled="!notation.length" class="search-top-button"><span class="glyphicon glyphicon-search"></span></button></form></div><div skos-concept="concept" skos-click="selectConcept" language="language"></div>'),$templateCache.put("template/skos-concept-thesaurus.html",'<div class="skos-concept-thesaurus"><ul ng-if="ancestors.length" class="ancestors"><li class="ancestor" ng-repeat="a in ancestors"><span class="ancestors-label" skos-label="a.prefLabel" lang="{{language}}" ng-click="update(a);reload();"></span> <span class="ancestors-greater">></span></li></ul><div class="top top-classic"><span ng-if="notation" class="notation">{{notation[0]}}</span> <b><span skos-label="concept.prefLabel" lang="{{language}}"></span></b><a ng-if="notation" class="uri" href="{{uri}}"><span style="vertical-align:-10%" class="glyphicon glyphicon-globe"></span></a></div><div ng-if="altLabel" class="skos-concept-altlabel"><ul><li ng-repeat="a in altLabel[language]" style="display:inline"><span ng-if="$index < 5" style="display:inline">{{a}}</span> <span style="margin-left:-4px;margin-right:3px" ng-if="$index < 4 && $index < altLabel[language].length-1">,</span></li></ul></div><div ng-if="broader.length" class="skos-concept-thesaurus-relation"><b>Broader Terms:</b><ul ng-repeat="b in broader"><li><span skos-label="b.prefLabel" lang="{{language}}" ng-click="click(b)"></li></ul></div><div ng-if="narrower.length" class="skos-concept-thesaurus-relation"><b>Narrower Terms:</b><ul ng-repeat="n in narrower"><li><span skos-label="n.prefLabel" lang="{{language}}" ng-click="click(n)"></li></ul></div><div ng-if="related.length" class="skos-concept-thesaurus-relation"><b>Related Terms:</b><ul ng-repeat="r in related"><li><span skos-label="r.prefLabel" lang="{{language}}" ng-click="click(r)"></li></ul></div><div ng-if="scopeNote.length"><div ng-repeat="n in scopeNote" class="skos-note skos-concept-thesaurus-note"><em><div skos-label="n" lang="{{language}}"></div></em></div></div><div ng-if="definition.length"><div ng-repeat="n in definition" class="skos-note skos-concept-thesaurus-note"><em><div skos-label="n" lang="{{language}}"></div></em></div></div></div>'),$templateCache.put("template/skos-concept.html",'<div class="skos-concept"><div class="top top-alt"><span ng-if="notation.length" class="notation">{{notation[0]}}</span> <b><span ng-if="prefLabel" skos-label="concept.prefLabel" lang="{{language}}"></span></b> <a ng-if="uri && uri != notation" class="uri" href="{{uri}}" target="_blank"><span class="glyphicon glyphicon-globe"></span></a></div><div ng-if="altLabel" class="skos-concept-altlabel"><ul><li ng-repeat="a in altLabel[language]"><span ng-if="$index < 5">{{a}}</span> <span style="margin-left:-4px;margin-right:3px" ng-if="$index < 4 && $index < altLabel[language].length-1">,</span></li></ul></div><div ng-if="broader.length || narrower.length || related.length" class="skos-concept-connected"><div ng-if="broader.length" class="skos-concept-relation skos-concept-relation-broader"><ul ng-repeat="c in broader"><li><div>↥</div><div class="skos-concept-relation-label"><span ng-if="c.prefLabel" skos-label="c.prefLabel" lang="{{language}}" ng-click="click(c)" title="{{c.notation[0]}}"></span> <span ng-if="!c.prefLabel" ng-click="click(c)">{{c.notation[0]}}</span></div></li></ul></div><div ng-if="narrower.length" class="skos-concept-relation skos-concept-relation-narrower"><ul ng-repeat="c in narrower"><li><div>↧</div><div class="skos-concept-relation-label"><span ng-if="c.prefLabel" skos-label="c.prefLabel" lang="{{language}}" ng-click="click(c)" title="{{c.notation[0]}}"></span> <span ng-if="!c.prefLabel" ng-click="click(c)">{{c.notation[0]}}</span></div></li></ul></div><div ng-if="related.length" class="skos-concept-relation skos-concept-relation-related"><ul ng-repeat="c in related"><li><div>↦</div><div class="skos-concept-relation-label"><span ng-if="c.prefLabel" skos-label="c.prefLabel" lang="{{language}}" ng-click="click(c)" title="{{c.notation[0]}}"></span> <span ng-if="!c.prefLabel" ng-click="click(c)">{{c.notation[0]}}</span></div></li></ul></div></div><div style="margin-bottom:10px"><div skos-notes="concept" lang="{{language}}"></div></div></div>'),$templateCache.put("template/skos-list.html",'<ul ng-if="concepts.length" class="skos-simple-list"><li ng-repeat="c in concepts"><div class="set" tabindex="0" ng-keydown="onKeyDown($event, $first, $last, $index)" list-index="{{listname + \'_\' + $index}}" ng-focus="onFocus($index)"><span ng-if="c.prefLabel" style="whitespace:nowrap" class="notation skos-list-notation" title="{{popOverTitle(c.prefLabel)}}" ng-click="onClick($index)">{{c.notation[0]}}</span> <span ng-if="!c.prefLabel" style="whitespace:nowrap" class="notation skos-list-notation" ng-click="onClick($index)">{{c.notation[0]}}</span> <span ng-if="showLabels && c.prefLabel" skos-label="c.prefLabel" lang="{{language}}" class="skos-list-label" ng-click="onClick($index)"></span><div style="display:inline-table;padding-left:3px"><a ng-if="onSelect" href="" ng-click="onSelect(c)" style="text-decoration:none;vertical-align:middle"><span class="glyphicon glyphicon-info-sign" title="Select concept (ENTER)"></span></a> <a ng-if="canRemove" href="" ng-click="removeConcept($index)" style="text-decoration:none;vertical-align:middle"><span class="glyphicon glyphicon-trash" title="Remove concept (DEL)"></span></a></div></div></li></ul>'),$templateCache.put("template/skos-mapping-table.html",'<table class="table table-hover table-condensed table-bordered mapping-table"><thead><tr><th class="mapping-table-scheme"><span>Source Scheme</span></th><th class="mapping-table-scheme"><span>Source Concept</span></th><th class="skos-mapping-cell skos-mapping-cell-center"><span>Target Scheme</span></th><th class="skos-mapping-cell skos-mapping-cell-center"><span>Target Concept(s)</span></th><th class="skos-mapping-cell skos-mapping-cell-center" ng-if="type"><span class="mapping-table-header-sortable">Type</span> <a ng-click="predicate = \'type.value\';reverse = !reverse" href="" class="mapping-table-icon"><span class="glyphicon glyphicon-sort"></span></a></th><th class="skos-mapping-cell skos-mapping-cell-center" style="min-width:80px"><span class="mapping-table-header-sortable">Creator</span> <a ng-click="predicate = \'creator\';reverse = !reverse" href="" class="mapping-table-icon"><span class="glyphicon glyphicon-sort"></span></a></th><th class="skos-mapping-cell skos-mapping-cell-center" style="min-width:120px"><span class="mapping-table-header-sortable">Last Change</span> <a ng-click="predicate = \'created\';reverse = !reverse" href="" class="mapping-table-icon"><span class="glyphicon glyphicon-sort"></span></a></th><th class="skos-mapping-cell skos-mapping-cell-center" style="min-width:100px"><span class="mapping-table-header-sortable">Relevance</span> <a ng-click="predicate = \'mappingRelevance\';reverse = !reverse" href="" class="mapping-table-icon"><span class="glyphicon glyphicon-sort"></span></a></th></tr></thead><tbody><tr ng-repeat="m in mapping | orderBy:predicate:reverse"><td class="skos-mapping-cell"><ul class="simple-list simple-list-center"><li><span ng-if="m.from.members[0].inScheme" class="classification">{{m.from.members[0].inScheme.notation[0]}}</span> <span ng-if="m.fromScheme && !m.from.members[0].inScheme" class="classification">{{m.fromScheme.notation}}</span></li></ul></td><td class="skos-mapping-cell"><ul class="simple-list"><li><span ng-if="m.from.members[0].prefLabel" class="notation" title="{{popOverTitle(m.from.members[0].prefLabel)}}">{{m.from.members[0].notation[0]}}</span> <span ng-if="!m.from.members[0].prefLabel" class="notation">{{m.from.members[0].notation[0]}}</span></li></ul></td><td class="skos-mapping-cell"><ul class="simple-list simple-list-center"><li><span ng-if="m.to.members[0].inScheme" class="classification">{{m.to.members[0].inScheme.notation[0]}}</span> <span ng-if="m.toScheme && !m.to.members[0].inScheme" class="classification">{{m.toScheme.notation}}</span></li></ul></td><td class="skos-mapping-cell"><ul class="simple-list"><li ng-repeat="t in m.to.members"><div class="skos-mapping-target"><span ng-if="t.prefLabel" class="notation" title="{{popOverTitle(t.prefLabel)}}">{{t.notation[0]}}</span> <span ng-if="!t.prefLabel" class="notation">{{t.notation[0]}}</span> <a ng-if="lookup && t.inScheme" ng-class="{ \'link-disabled\': t.inScheme.notation[0] != schemes.target }" title="Select concept" class="mapping-action-icon"><span ng-click="lookup(t, m.to.members[0].inScheme.notation[0])"><span style="top:2px" class="glyphicon glyphicon-info-sign"></span></span></a> <a ng-if="lookup && !t.inScheme" ng-class="{ \'link-disabled\': m.toScheme.notation != schemes.target }" title="Select concept" class="mapping-action-icon"><span ng-click="lookup(t, m.toScheme.notation)"><span style="top:2px" class="glyphicon glyphicon-info-sign"></span></span></a> <a ng-if="select && t.inScheme" ng-class="{ \'link-disabled\': t.inScheme.notation[0] != schemes.target }" title="Add concept to mapping" class="mapping-action-icon"><span ng-click="select(t, m.to.members[0].inScheme.notation[0])"><span style="" class="glyphicon glyphicon-plus"></span></span></a> <a ng-if="select && !t.inScheme" ng-class="{ \'link-disabled\': m.toScheme.notation != schemes.target }" title="Add concept to mapping" class="mapping-action-icon"><span ng-click="select(t, m.toScheme.notation)"><span style="" class="glyphicon glyphicon-plus"></span></span></a></div></li></ul></td><td ng-if="type">{{m.type.prefLabel}}</td><td class="skos-mapping-cell skos-mapping-cell-center"><a ng-if="m.creator[0].uri" href="{{m.creator[0].uri}}" target="_blank"><span ng-if="m.creator[0].prefLabel" skos-label="m.creator[0].prefLabel" lang="{{language}}"></span> <span ng-if="!m.creator[0].prefLabel">{{m.creator[0].uri}}</span></a> <span ng-if="m.creator[0].prefLabel && !m.creator[0].uri" skos-label="m.creator[0].prefLabel" lang="{{language}}"></span></td><td class="skos-mapping-cell skos-mapping-cell-center"><span ng-if="!m.modified && !m.issued && m.created">{{m.created}} (created)</span> <span ng-if="!m.modified && m.issued">{{m.issued}} (issued)</span> <span ng-if="m.modified">{{m.modified}} (modified)</span></td><td class="skos-mapping-cell skos-mapping-cell-center"><span ng-if="m.mappingType">{{m.mappingType}} ({{m.mappingRelevance}})</span> <span ng-if="!m.mappingType && m.mappingRelevance">{{m.mappingRelevance}}</span></td></tr></tbody></table>'),$templateCache.put("template/skos-notes.html",'<ul ng-repeat="n in scopeNote[language]" class="skos-note skos-note-scopeNote"><li ng-if="$index < 5">{{n}}</li></ul><ul ng-repeat="n in definition[language]" class="skos-note skos-note-definition"><li ng-if="$index < 5">{{n}}</li></ul><ul ng-repeat="n in example[language]" class="skos-note skos-note-example"><li ng-if="$index < 5">{{n}}</li></ul><ul ng-repeat="n in historyNote[language]" class="skos-note skos-note-historyNote"><li ng-if="$index < 5">{{n}}</li></ul>'),$templateCache.put("template/skos-tree.html",'<div style="" class="skos-tree"><p class="set" ng-if="!tree.topConcepts"><span ng-if="tree.notation.length" class="notation" style="white-space:nowrap">{{tree.notation[0]}}</span> <span skos-label="tree.prefLabel" lang="{{language}}" style="padding-left:3px"></span></p><ul><li ng-repeat="n in tree.narrower ? tree.narrower : tree.topConcepts"><span skos-tree="n" language="language"></span></li></ul></div>')}]);