Project

General

Profile

« Previous | Next » 

Revision 41867

vocabulary ui

View differences:

modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/js/modalRelation.js
1
var module = angular.module('modalRelation', []);
2

  
3
module.directive('modalRelation', function(){
4
	return {
5
		restrict: 'E',
6
		templateUrl: '../resources/html/vocabularies/modalRelation.html',
7
		controller: function($scope) {
8
			$scope.showRelModal = function(term, rel) {
9
				$scope.selectedTermIndex = $scope.entries.indexOf(term);
10
				$scope.selectedRelIndex = $scope.entries[$scope.selectedTermIndex].relations.indexOf(rel);
11
				if (rel != null) {
12
					// edit existing synonym
13
					$scope.modalRel.refTerm = $scope.entries[$scope.selectedTermIndex].englishName;
14
					$scope.modalRel.code = $scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].code;
15
					$scope.modalRel.type = $scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].type;
16
				} else {
17
					// new synonym
18
					$scope.modalRel.refTerm = $scope.entries[$scope.selectedTermIndex].englishName;
19
					$scope.modalRel.code = '';
20
					$scope.modalRel.type = '';
21
				}
22
				$('#relModal').modal();
23
			};
24

  
25
			$scope.editRel = function() {
26
				if ($scope.selectedRelIndex == -1) {
27
					$scope.entries[$scope.selectedTermIndex].relations.push({
28
						"code" : $scope.modalRel.code,
29
						"type" : $scope.modalRel.type
30
					});
31
				} else {
32
					$scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].code = $scope.modalRel.code;
33
					$scope.entries[$scope.selectedTermIndex].relations[$scope.selectedRelIndex].type = $scope.modalRel.type;
34
				}
35
				// dismiss modal
36
				$('.modal').modal('hide');
37
				if ($scope.autocommit) {
38
					$scope.commit();
39
				} else {
40
					showPermanotice("Uncommitted changes!");
41
				}
42
			}
43
		},
44
		controllerAs: 'modalRelation'
45
	};
46
});
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/js/modalInfo.js
1
var module = angular.module('modalInfo', []);
2

  
3
module.directive('modalInfo', function(){
4
	return {
5
		restrict: 'E',
6
		templateUrl: '../resources/html/vocabularies/modalInfo.html',
7
		controller: function($scope, $http){
8
			$scope.showInfoModal = function() {
9
				if ($scope.selectedVocabularyIndex != null) {
10
					// show modal for editing info of existing vocabulary
11
					$scope.modalInfo.id = $scope.vocabularies[$scope.selectedVocabularyIndex].id;
12
					$scope.modalInfo.name = $scope.vocabularies[$scope.selectedVocabularyIndex].name;
13
					$scope.modalInfo.code = $scope.vocabularies[$scope.selectedVocabularyIndex].code;
14
					$scope.modalInfo.description = $scope.vocabularies[$scope.selectedVocabularyIndex].description;
15
				} else {
16
					// show modal for new vocabulary
17
					$scope.modalInfo.id = '';
18
					$scope.modalInfo.name = '';
19
					$scope.modalInfo.code = '';
20
					$scope.modalInfo.description = '';
21
					hidePermanotice();
22
				}
23
				$('#infoModal').modal();
24
			}
25
			
26
			$scope.editInfo = function() {
27
				showSpinner();
28
				if ($scope.selectedVocabularyIndex == null) {
29
					// new vocabulary
30
					$http.post('createVocabulary', 
31
								{"name" : $scope.modalInfo.name, 
32
								"code" : $scope.modalInfo.code, 
33
								"description" : $scope.modalInfo.description})
34
						.success(
35
							function(data) {
36
								show_notification("success", "Vocabulary created successfully!");
37
								$scope.vocabularies.push({
38
									"id" : data,
39
									"name" : $scope.modalInfo.name,
40
									"code" : $scope.modalInfo.code,
41
									"description" : $scope.modalInfo.description
42
								});
43
								hideSpinner();
44
								$scope.loadVocabularies();
45
							})
46
						.error(
47
							function() {
48
								show_notification("error", "Cannot edit info..");
49
								hideSpinner();
50
							});
51
				} else {
52
					// edit vocabulary
53
					$http.post('commitVocabularyInfo?vocabularyId=' + $scope.vocabularies[$scope.selectedVocabularyIndex].id, 
54
								{"name" : $scope.modalInfo.name, 
55
								"code" : $scope.modalInfo.code, 
56
								"description" : $scope.modalInfo.description})
57
						.success(
58
							function() {
59
								// update model
60
								$scope.vocabularies[$scope.selectedVocabularyIndex].id = $scope.modalInfo.id;
61
								$scope.vocabularies[$scope.selectedVocabularyIndex].name = $scope.modalInfo.name;
62
								$scope.vocabularies[$scope.selectedVocabularyIndex].code = $scope.modalInfo.code;
63
								$scope.vocabularies[$scope.selectedVocabularyIndex].description = $scope.modalInfo.description;
64
								show_notification("success", "Vocabulary information saved correctly!");
65
								hideSpinner();
66
								$scope.loadVocabularies();
67
							})
68
						.error(
69
							function() {
70
								show_notification("error", "Cannot edit info..");
71
								hideSpinner();
72
							});
73
				}
74
				// dismiss modal
75
				$('.modal').modal('hide');
76
			}
77
		},
78
		controllerAs: 'modalInfo'
79
	};
80
});
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/model/Term.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.model;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
public class Term implements Comparable<Term> {
7
	private String englishName;
8
	private String nativeName;
9
	private String encoding;
10
	private String code;
11
	private List<Synonym> synonyms = new ArrayList<Synonym>();
12
	private List<Relation> relations = new ArrayList<Relation>();
13
	
14
	public Term() {}
15
	
16
	public Term(String englishName, String nativeName, String encoding,
17
			String code, List<Synonym> synonyms, List<Relation> relations) {
18
		super();
19
		this.englishName = englishName;
20
		this.nativeName = nativeName;
21
		this.encoding = encoding;
22
		this.code = code;
23
		this.synonyms = synonyms;
24
		this.relations = relations;
25
	}
26

  
27
	public String getEnglishName() {
28
		return englishName;
29
	}
30

  
31
	public void setEnglishName(String englishName) {
32
		this.englishName = englishName;
33
	}
34

  
35
	public String getNativeName() {
36
		return nativeName;
37
	}
38

  
39
	public void setNativeName(String nativeName) {
40
		this.nativeName = nativeName;
41
	}
42

  
43
	public String getEncoding() {
44
		return encoding;
45
	}
46

  
47
	public void setEncoding(String encoding) {
48
		this.encoding = encoding;
49
	}
50

  
51
	public String getCode() {
52
		return code;
53
	}
54

  
55
	public void setCode(String code) {
56
		this.code = code;
57
	}
58

  
59
	public List<Synonym> getSynonyms() {
60
		return synonyms;
61
	}
62

  
63
	public void setSynonyms(List<Synonym> synonyms) {
64
		this.synonyms = synonyms;
65
	}
66

  
67
	public List<Relation> getRelations() {
68
		return relations;
69
	}
70

  
71
	public void setRelations(List<Relation> relations) {
72
		this.relations = relations;
73
	}
74

  
75
	@Override
76
	public int compareTo(Term o) {
77
		return englishName.compareTo(o.getEnglishName());
78
	}
79

  
80
}
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/model/Vocabulary.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.model;
2

  
3
public class Vocabulary implements Comparable<Vocabulary> {
4
	private String id;
5
	private String name;
6
	private String description;
7
	private String code;
8

  
9
	public Vocabulary() {}
10
	
11
	public Vocabulary(String id, String name, String description, String code) {
12
		super();
13
		this.id = id;
14
		this.name = name;
15
		this.description = description;
16
		this.code = code;
17
	}
18

  
19
	public String getId() {
20
		return id;
21
	}
22

  
23
	public void setId(String id) {
24
		this.id = id;
25
	}
26

  
27
	public String getName() {
28
		return name;
29
	}
30

  
31
	public void setName(String name) {
32
		this.name = name;
33
	}
34

  
35
	public String getDescription() {
36
		return description;
37
	}
38

  
39
	public void setDescription(String description) {
40
		this.description = description;
41
	}
42

  
43
	public String getCode() {
44
		return code;
45
	}
46

  
47
	public void setCode(String code) {
48
		this.code = code;
49
	}
50

  
51
	@Override
52
	public int compareTo(Vocabulary o) {
53
		return name.compareTo(o.getName());
54
	}
55
}
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/model/Synonym.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.model;
2

  
3
public class Synonym implements Comparable<Synonym> {
4
	private String term;
5
	private String encoding;	
6
	
7
	public Synonym() {}
8
	
9
	public Synonym(String term, String encoding) {
10
		super();
11
		this.term = term;
12
		this.encoding = encoding;
13
	}
14

  
15
	public String getTerm() {
16
		return term;
17
	}
18

  
19
	public void setTerm(String term) {
20
		this.term = term;
21
	}
22

  
23
	public String getEncoding() {
24
		return encoding;
25
	}
26

  
27
	public void setEncoding(String encoding) {
28
		this.encoding = encoding;
29
	}
30
	
31
	@Override
32
	public int compareTo(Synonym o) {
33
		return term.compareTo(o.getTerm());
34
	}
35
}
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/model/Relation.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.model;
2

  
3
public class Relation implements Comparable<Relation> {
4

  
5
	private String type;
6
	private String code;
7

  
8
	public Relation() {}
9

  
10
	public Relation(final String type, final String code) {
11
		super();
12
		this.type = type;
13
		this.code = code;
14
	}
15

  
16
	public String getType() {
17
		return type;
18
	}
19

  
20
	public void setType(final String type) {
21
		this.type = type;
22
	}
23

  
24
	@Override
25
	public int compareTo(final Relation o) {
26
		return code.compareTo(o.getCode());
27
	}
28

  
29
	public String getCode() {
30
		return code;
31
	}
32

  
33
	public void setCode(final String code) {
34
		this.code = code;
35
	}
36
}
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/persistence/RegistryServiceVocabularyDAO.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.persistence;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.util.ArrayList;
6
import java.util.Collections;
7
import java.util.List;
8
import java.util.Map;
9

  
10
import org.antlr.stringtemplate.StringTemplate;
11
import org.apache.commons.io.IOUtils;
12
import org.apache.commons.lang3.StringEscapeUtils;
13
import org.dom4j.Document;
14
import org.dom4j.DocumentException;
15
import org.dom4j.Element;
16
import org.dom4j.io.SAXReader;
17

  
18
import com.google.common.base.Function;
19
import com.google.common.collect.Lists;
20
import com.google.common.collect.Maps;
21

  
22
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Relation;
23
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Synonym;
24
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Term;
25
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Vocabulary;
26
import eu.dnetlib.miscutils.datetime.DateUtils;
27
import eu.dnetlib.rmi.enabling.ISLookUpDocumentNotFoundException;
28
import eu.dnetlib.rmi.enabling.ISLookUpException;
29
import eu.dnetlib.rmi.enabling.ISLookUpService;
30
import eu.dnetlib.rmi.enabling.ISRegistryDocumentNotFoundException;
31
import eu.dnetlib.rmi.enabling.ISRegistryException;
32
import eu.dnetlib.rmi.enabling.ISRegistryService;
33

  
34
public class RegistryServiceVocabularyDAO extends VocabularyDAO {
35

  
36
	@Override
37
	public List<Vocabulary> getVocabularies() throws VocabularyException {
38
		try {
39
			final String query =
40
					"for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType') order by $x//VOCABULARY_NAME "
41
							+ "return concat ($x//RESOURCE_IDENTIFIER/@value,' §§§ ',$x//VOCABULARY_NAME,' §§§ ',$x//VOCABULARY_DESCRIPTION,' §§§ ',$x//VOCABULARY_NAME/@code)";
42

  
43
			final List<Vocabulary> vocabularies = Lists.transform(this.serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query),
44
					new Function<String, Vocabulary>() {
45

  
46
						@Override
47
						public Vocabulary apply(final String s) {
48
							final String[] tokens = s.split("§§§");
49
							return new Vocabulary(tokens[0].trim(), tokens[1].trim(), tokens[2].trim(), tokens[3].trim());
50
						}
51
					});
52
			return vocabularies;
53
		} catch (final ISLookUpException e) {
54
			throw new VocabularyException(e);
55
		}
56
	}
57

  
58
	@Override
59
	public List<Term> getTerms(final String vocabularyId) throws VocabularyException {
60
		try {
61
			final String profile = this.serviceLocator.getService(ISLookUpService.class).getResourceProfile(vocabularyId);
62
			final Document doc = new SAXReader().read(new StringReader(profile));
63
			final Map<String, Term> terms = Maps.newHashMap();
64

  
65
			for (final Object t : doc.selectNodes("//TERM")) {
66
				final Element termNode = (Element) t;
67
				final String code = termNode.valueOf("@code");
68

  
69
				if (!terms.containsKey(code)) {
70
					final Term term = new Term();
71
					term.setEnglishName(termNode.valueOf("@english_name"));
72
					term.setNativeName(termNode.valueOf("@native_name"));
73
					term.setEncoding(termNode.valueOf("@encoding"));
74
					term.setCode(code);
75
					term.setSynonyms(new ArrayList<Synonym>());
76
					term.setRelations(new ArrayList<Relation>());
77
					terms.put(code, term);
78
				}
79
				final Term term = terms.get(code);
80

  
81
				for (final Object s : termNode.selectNodes(".//SYNONYM")) {
82
					final Element synNode = (Element) s;
83
					final Synonym syn = new Synonym();
84
					syn.setTerm(synNode.valueOf("@term"));
85
					syn.setEncoding(synNode.valueOf("@encoding"));
86
					term.getSynonyms().add(syn);
87
				}
88

  
89
				for (final Object r : termNode.selectNodes(".//RELATION")) {
90
					final Element relNode = (Element) r;
91
					final Relation rel = new Relation();
92
					rel.setCode(relNode.valueOf("@code"));
93
					rel.setType(relNode.valueOf("@type"));
94
					term.getRelations().add(rel);
95
				}
96

  
97
				Collections.sort(term.getSynonyms());
98
				Collections.sort(term.getRelations());
99
			}
100

  
101
			final List<Term> list = Lists.newArrayList(terms.values());
102
			Collections.sort(list);
103

  
104
			return list;
105
		} catch (final ISLookUpDocumentNotFoundException e) {
106
			throw new VocabularyException(e);
107
		} catch (final ISLookUpException e) {
108
			throw new VocabularyException(e);
109
		} catch (final DocumentException e) {
110
			throw new VocabularyException(e);
111
		}
112
	}
113

  
114
	@Override
115
	public void commitTerms(final List<Term> terms, final String vocabularyId) throws VocabularyException {
116
		try {
117
			// prepare terms for XML
118
			for (final Term t : terms) {
119
				t.setCode(StringEscapeUtils.escapeXml(t.getCode()));
120
				t.setEncoding(StringEscapeUtils.escapeXml(t.getEncoding()));
121
				t.setEnglishName(StringEscapeUtils.escapeXml(t.getEnglishName()));
122
				t.setNativeName(StringEscapeUtils.escapeXml(t.getNativeName()));
123
				for (final Synonym s : t.getSynonyms()) {
124
					s.setEncoding(StringEscapeUtils.escapeXml(s.getEncoding()));
125
					s.setTerm(StringEscapeUtils.escapeXml(s.getTerm()));
126
				}
127
				for (final Relation r : t.getRelations()) {
128
					r.setType(StringEscapeUtils.escapeXml(r.getType()));
129
					r.setCode(StringEscapeUtils.escapeXml(r.getCode()));
130
				}
131
			}
132

  
133
			final StringTemplate st =
134
					new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/terms.xml.st")));
135
			st.setAttribute("terms", terms);
136
			this.serviceLocator.getService(ISRegistryService.class).updateProfileNode(vocabularyId, "//TERMS", st.toString());
137
		} catch (final IOException e) {
138
			throw new VocabularyException(e);
139
		} catch (final ISRegistryException e) {
140
			throw new VocabularyException(e);
141
		}
142

  
143
	}
144

  
145
	@Override
146
	public void commitVocabularyInfo(final Vocabulary voc, final String vocabularyId) throws VocabularyException {
147
		try {
148
			String xml = "<VOCABULARY_DESCRIPTION>{desc}</VOCABULARY_DESCRIPTION>";
149
			xml = xml.replace("{desc}", StringEscapeUtils.escapeXml(voc.getDescription()));
150
			this.serviceLocator.getService(ISRegistryService.class).updateProfileNode(vocabularyId, "//VOCABULARY_DESCRIPTION", xml);
151
		} catch (final ISRegistryException e) {
152
			throw new VocabularyException(e);
153
		}
154
	}
155

  
156
	@Override
157
	public String createVocabulary(final Vocabulary voc) throws VocabularyException {
158
		try {
159
			final StringTemplate st = new StringTemplate(
160
					IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/templates/vocabulary.xml.st")));
161
			st.setAttribute("name", voc.getName());
162
			st.setAttribute("description", voc.getDescription());
163
			st.setAttribute("code", voc.getCode());
164
			st.setAttribute("date", DateUtils.now_ISO8601());
165
			final String newVocabularyId = this.serviceLocator.getService(ISRegistryService.class).registerProfile(st.toString());
166

  
167
			return newVocabularyId;
168
		} catch (final IOException e) {
169
			throw new VocabularyException(e);
170
		} catch (final ISRegistryException e) {
171
			throw new VocabularyException(e);
172
		}
173
	}
174

  
175
	@Override
176
	public void dropVocabulary(final String vocabularyId) throws VocabularyException {
177
		try {
178
			this.serviceLocator.getService(ISRegistryService.class).deleteProfile(vocabularyId);
179
		} catch (final ISRegistryDocumentNotFoundException e) {
180
			throw new VocabularyException(e);
181
		} catch (final ISRegistryException e) {
182
			throw new VocabularyException(e);
183
		}
184
	}
185

  
186
}
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/persistence/VocabularyException.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.persistence;
2

  
3

  
4
public class VocabularyException extends Exception {
5

  
6
	/**
7
	 *
8
	 */
9
	private static final long serialVersionUID = 1L;
10

  
11
	Exception exception;
12

  
13
	public VocabularyException(final Exception e) {
14
		this.exception = e;
15
	}
16
}
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/persistence/VocabularyDAO.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.persistence;
2

  
3
import java.util.List;
4

  
5
import javax.annotation.Resource;
6

  
7
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
8
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Term;
9
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Vocabulary;
10

  
11
public abstract class VocabularyDAO {
12

  
13
	@Resource
14
	protected UniqueServiceLocator serviceLocator;
15

  
16
	public abstract List<Vocabulary> getVocabularies() throws VocabularyException;
17

  
18
	public abstract List<Term> getTerms(final String vocabularyId) throws VocabularyException;
19

  
20
	public abstract void commitTerms(final List<Term> terms, final String vocabularyId) throws VocabularyException;
21

  
22
	public abstract void commitVocabularyInfo(final Vocabulary voc, final String vocabularyId) throws VocabularyException;
23

  
24
	public abstract String createVocabulary(final Vocabulary voc) throws VocabularyException;
25

  
26
	public abstract void dropVocabulary(final String vocabularyId) throws VocabularyException;
27

  
28
}
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/controllers/EntryPointController.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.controllers;
2

  
3
import javax.servlet.http.HttpServletRequest;
4
import javax.servlet.http.HttpServletResponse;
5

  
6
import org.apache.commons.io.IOUtils;
7
import org.springframework.ui.ModelMap;
8

  
9
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
10

  
11
public class EntryPointController extends ModuleEntryPoint {
12
	
13
	@Override
14
	protected void initialize(ModelMap map, HttpServletRequest request,	HttpServletResponse response) throws Exception {
15
		map.addAttribute("validRelations", IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/ui/term_relations.json"))); 
16
	}
17
}	
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/vocabularies/controllers/VocabulariesController.java
1
package eu.dnetlib.functionality.modular.ui.vocabularies.controllers;
2

  
3
import java.util.List;
4

  
5
import javax.annotation.Resource;
6

  
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.springframework.stereotype.Controller;
10
import org.springframework.web.bind.annotation.RequestBody;
11
import org.springframework.web.bind.annotation.RequestMapping;
12
import org.springframework.web.bind.annotation.RequestMethod;
13
import org.springframework.web.bind.annotation.RequestParam;
14
import org.springframework.web.bind.annotation.ResponseBody;
15

  
16
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Term;
17
import eu.dnetlib.functionality.modular.ui.vocabularies.model.Vocabulary;
18
import eu.dnetlib.functionality.modular.ui.vocabularies.persistence.VocabularyDAO;
19
import eu.dnetlib.functionality.modular.ui.vocabularies.persistence.VocabularyException;
20

  
21
/**
22
 * Web controller for the UI
23
 *
24
 * @author Andrea Mannocci
25
 */
26
@Controller
27
public class VocabulariesController extends VocabularyDAO {
28

  
29
	private static final Log log = LogFactory.getLog(VocabulariesController.class);
30

  
31
	@Resource(name = "vocabularyDao")
32
	private VocabularyDAO dao;
33

  
34
	/**
35
	 * Returns all vocabularies serialized in json. Invoked by angularJS
36
	 */
37
	@Override
38
	@RequestMapping("/ui/vocabularies.json")
39
	public @ResponseBody List<Vocabulary> getVocabularies() throws VocabularyException {
40
		log.info("vocabularies.json");
41
		return dao.getVocabularies();
42
	}
43

  
44
	/**
45
	 * Returns all terms and their synonyms belonging to a vocabulary. Invoked by AngularJS
46
	 */
47
	@Override
48
	@RequestMapping("/ui/terms.json")
49
	public @ResponseBody List<Term> getTerms(@RequestParam(value = "vocabularyId", required = true) final String vocabularyId) throws VocabularyException {
50
		log.info("terms.json?vocabularyId=" + vocabularyId);
51
		return dao.getTerms(vocabularyId);
52
	}
53

  
54
	@Override
55
	@RequestMapping(value = "/ui/commitVocabulary", method = RequestMethod.POST)
56
	public @ResponseBody void commitTerms(@RequestBody(required = true) final List<Term> terms,
57
			@RequestParam(value = "vocabularyId", required = true) final String vocabularyId) throws VocabularyException {
58
		log.info("committing vocabulary id = " + vocabularyId);
59
		dao.commitTerms(terms, vocabularyId);
60
	}
61

  
62
	@Override
63
	@RequestMapping(value = "/ui/commitVocabularyInfo", method = RequestMethod.POST)
64
	public @ResponseBody void commitVocabularyInfo(@RequestBody(required = true) final Vocabulary voc,
65
			@RequestParam(value = "vocabularyId", required = true) final String vocabularyId) throws VocabularyException {
66
		log.info("committing vocabulary info id = " + vocabularyId);
67
		dao.commitVocabularyInfo(voc, vocabularyId);
68
	}
69

  
70
	@Override
71
	@RequestMapping(value = "/ui/createVocabulary", method = RequestMethod.POST)
72
	public @ResponseBody String createVocabulary(@RequestBody(required = true) final Vocabulary voc) throws VocabularyException {
73
		log.info("create vocabulary");
74
		String vocId = dao.createVocabulary(voc);
75
		return vocId;
76
	}
77

  
78
	@Override
79
	@RequestMapping(value = "/ui/dropVocabulary", method = RequestMethod.GET)
80
	public @ResponseBody void dropVocabulary(@RequestParam(value = "vocabularyId", required = true) final String vocabularyId) throws VocabularyException {
81
		log.info("delete vocabulary id=" + vocabularyId);
82
		dao.dropVocabulary(vocabularyId);
83
	}
84
}
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/applicationContext-modular-ui-vocabularies.properties
1
dnet.modular.ui.vocabulary.dao = registryServiceVocabularyDAO
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/vocabularies.st
1
$common/master( header={
2
	<script type="text/javascript" src="../resources/js/angular.min.js"></script>
3
	<script type="text/javascript" src="../resources/js/vocabularies.js"></script>
4
	<script type="text/javascript" src="../resources/js/uniqueChecker.js"></script>
5
	<script type="text/javascript" src="../resources/js/modalTerm.js"></script>
6
	<script type="text/javascript" src="../resources/js/modalInfo.js"></script>
7
	<script type="text/javascript" src="../resources/js/modalSynonym.js"></script>
8
	<script type="text/javascript" src="../resources/js/modalRelation.js"></script>
9
	<script type="text/javascript">
10
		function getValidRelations() {
11
			return $if(validRelations)$$validRelations$$else$[]$endif$;
12
		}
13
	</script>
14
}, body={
15
	<div ng-app="vocabulariesUI" ng-controller="vocabulariesCtrl">
16
		<div class="row">
17
			<vocabulary-list></vocabulary-list>
18
			
19
			<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9" ng-show="entries != null && selectedVocabularyIndex != null" >
20
				<form role="form" class="form-inline">
21
					<div class="btn-group">
22
						<button type="button" class="btn btn-default" ng-click="showInfoModal()">
23
							Edit info <span class="glyphicon glyphicon-book"></span>
24
						</button>
25
						<button type="button" class="btn btn-default" ng-click="showTermModal(null)">
26
							New Term <span class="glyphicon glyphicon-pencil"></span>
27
						</button>
28
						<button type="button" class="btn btn-default" ng-click="commit()" ng-show="!autocommit">
29
							Commit <span class="glyphicon glyphicon-floppy-saved"></span>
30
						</button>
31
						<button type="button" class="btn btn-default" ng-click="reloadTerms()" ng-show="!autocommit">
32
							Discard all <span class="glyphicon glyphicon-repeat"></span>
33
						</button>
34
						<button type="button" class="btn btn-default" ng-click="reloadTerms()" ng-show="autocommit">
35
                            Refresh from IS <span class="glyphicon glyphicon-refresh"></span>
36
                        </button>
37
						<button type="button" class="btn btn-default" ng-click="dropVocabulary()">
38
							Drop vocabulary <span class="glyphicon glyphicon-trash"></span>
39
						</button>
40
					</div>
41
					<div class="checkbox">
42
                        <label><input type="checkbox" ng-model="autocommit"> Auto-commit</label>
43
                    </div>
44
					<div class="form-group pull-right">
45
						<input type="text" class="form-control" ng-model="termFilter" placeholder="Filter by...">
46
					</div>
47
				</form>
48
				<br><br>
49
				
50
				<term-list></term-list>
51
			</div>
52
		</div>
53
			
54
		<!-- infoModal -->
55
		<modal-info></modal-info>
56
		
57
		<!-- term Modal -->
58
		<modal-term></modal-term>
59
		
60
		<!-- synonymModal -->
61
		<modal-synonym></modal-synonym>
62

  
63
		<!-- relModal -->
64
		<modal-relation></modal-relation>
65
		
66
	</div>
67
} )$
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/term_relations.json
1
[
2
	{ "id": "owl:complementOf",         "label": "complementOf" },
3
	{ "id": "owl:differentFrom",        "label": "differentFrom" },
4
	{ "id": "owl:disjointUnionOf",      "label": "disjointUnionOf" },
5
	{ "id": "owl:disjointWith",         "label": "disjointWith" },
6
	{ "id": "owl:equivalentClass",      "label": "equivalentClass" },
7
	{ "id": "owl:incompatibleWith",     "label": "incompatibleWith" },
8
	{ "id": "owl:inverseOf",            "label": "inverseOf" },
9
	{ "id": "owl:propertyDisjointWith", "label": "propertyDisjointWith" },
10
	{ "id": "owl:sameAs",               "label": "sameAs" },
11
	{ "id": "owl:someValuesFrom",       "label": "someValuesFrom" },
12
	{ "id": "owl:unionOf",              "label": "unionOf" },
13
	{ "id": "skos:broader",       		"label": "broaderConcept" },
14
	{ "id": "skos:narrower",       		"label": "narrowerConcept" }
15
]
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/applicationContext-modular-ui-vocabularies.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<beans xmlns="http://www.springframework.org/schema/beans"
4
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
6

  
7
	<bean name="registryServiceVocabularyDAO" class="eu.dnetlib.functionality.modular.ui.vocabularies.persistence.RegistryServiceVocabularyDAO" />
8
	<alias name="${dnet.modular.ui.vocabulary.dao}" alias="vocabularyDao"/>
9
</beans>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/webContext-modular-ui-vocabularies.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<beans xmlns="http://www.springframework.org/schema/beans"
4
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
6

  
7
	<bean name="/ui/vocabularies.do"
8
		class="eu.dnetlib.functionality.modular.ui.vocabularies.controllers.EntryPointController"
9
		p:menu="Vocabulary editor" 
10
		p:title="D-NET vocabulary editor"
11
		p:description="D-NET vocabulary editor" 
12
		p:group="Configuration">
13
		<property name="permissionLevels">
14
			<set>
15
				<value>USER</value>
16
			</set>
17
		</property>
18
	</bean>
19
	
20
</beans>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/functionality/modular/templates/vocabulary.xml.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<RESOURCE_PROFILE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
	<HEADER>
4
		<RESOURCE_IDENTIFIER value="" />
5
		<RESOURCE_TYPE value="VocabularyDSResourceType" />
6
		<RESOURCE_KIND value="VocabularyDSResources" />
7
		<RESOURCE_URI value="String" />
8
		<DATE_OF_CREATION value="$date$" />
9
	</HEADER>
10
	<BODY>
11
		<CONFIGURATION>
12
			<VOCABULARY_NAME code="$code$">$name$</VOCABULARY_NAME>
13
			<VOCABULARY_DESCRIPTION>$description$</VOCABULARY_DESCRIPTION>
14
			<TERMS>
15
				<TERM english_name="Example" encoding="en" native_name="Example" code="0000">
16
					<SYNONYMS>
17
						<SYNONYM encoding="it" term="Esempio" />
18
						<SYNONYM encoding="es" term="Ejemplo" />
19
						<SYNONYM encoding="el" term="μάθημα" />
20
						<SYNONYM encoding="zh" term="鉴戒" />
21
						<SYNONYM encoding="ja" term="事例" />
22
						<SYNONYM encoding="ru" term="пример" />
23
					</SYNONYMS>
24
					<RELATIONS />
25
				</TERM>
26
			</TERMS>
27
		</CONFIGURATION>
28
		<STATUS>
29
			<LAST_UPDATE value="$date$" />
30
		</STATUS>
31
		<SECURITY_PARAMETERS />
32
	</BODY>
33
</RESOURCE_PROFILE>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/functionality/modular/templates/terms.xml.st
1
<TERMS>
2
	$terms:{t|
3
	<TERM native_name="$t.nativeName$" code="$t.code$" english_name="$t.englishName$" encoding="$t.encoding$">
4
        <SYNONYMS>
5
        	$t.synonyms:{s|
6
            <SYNONYM term="$s.term$" encoding="$s.encoding$"/>
7
            }$
8
        </SYNONYMS>
9
        <RELATIONS>
10
        	$t.relations:{r|
11
            <RELATION type="$r.type$" code="$r.code$"/>
12
            }$
13
        </RELATIONS>
14
    </TERM>
15
	}$
16
</TERMS>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/html/vocabularies/term-list.html
1
<div class="panel-group" id="TermsAccordion">
2
	<div class="panel panel-default"
3
		ng-repeat="term in entries | filter:termFilter">
4
		<div class="panel-heading">
5
			<h4 class="panel-title">
6
				 <a data-toggle="collapse" data-parent="#accordion"
7
					href="#accordionTerm{{$index}}"><strong>{{term.code}}</strong> <br/> <span class="text-muted">{{term.englishName}}</span></a> <span
8
					class="pull-right">
9
					<button type="button" class="btn btn-xs btn-primary " ng-click="showTermModal(term)">
10
						<span class="glyphicon glyphicon-pencil"></span>
11
					</button>
12
					<button type="button" class="btn btn-xs btn-danger " ng-click="deleteTerm(term)">
13
						<span class="glyphicon glyphicon-trash"></span>
14
					</button>
15
				</span>
16
			</h4>
17
		</div>
18
		<div id="accordionTerm{{$index}}" class="panel-collapse collapse">
19
			<div class="panel-body">
20
				<ul class="nav nav-tabs">
21
					<li class="active"><a href="#accordionTerm{{$index}}_synonyms"
22
						data-toggle="tab">Synonyms</a></li>
23
					<li><a href="#accordionTerm{{$index}}_rels" data-toggle="tab">Relations</a></li>
24
				</ul>
25
				<div class="tab-content" style="margin-top: 10px;">
26
					<div class="tab-pane active" id="accordionTerm{{$index}}_synonyms">
27
						<p class="text-muted" ng-hide="term.synonyms.length > 0">No synonyms</p>
28
						<table class="table table-bordered table-striped" ng-show="term.synonyms.length > 0">
29
							<th>Synonym</th>
30
							<th>Encoding</th>
31
							<th>Operation</th>
32
							<tr ng-repeat="synonym in term.synonyms">
33
								<td class="col-md-8">{{synonym.term}}</td>
34
								<td class="col-md-4">{{synonym.encoding}}</td>
35
								<td class="col-md-1">
36
									<button type="button" class="btn btn-xs btn-primary" ng-click="showSynonymModal(term, synonym)">
37
										<span class="glyphicon glyphicon-pencil"></span>
38
									</button>
39
									<button type="button" class="btn btn-xs btn-danger" ng-click="deleteSynonym(term, synonym)">
40
										<span class="glyphicon glyphicon-trash"></span>
41
									</button>
42
								</td>
43
							</tr>
44
						</table>
45
						<button class="btn btn-xs btn-primary" type="button"
46
							ng-click="showSynonymModal(term, null)">
47
							<span class="glyphicon glyphicon-plus"></span>
48
						</button>
49
					</div>
50
					<div class="tab-pane" id="accordionTerm{{$index}}_rels">
51
						<p class="text-muted" ng-hide="term.relations.length > 0">No relations</p>
52
						<table class="table table-bordered table-striped" ng-show="term.relations.length > 0">
53
							<th>Related Term</th>
54
							<th>Relation Type</th>
55
							<th>Operation</th>
56
							<tr ng-repeat="rel in term.relations">
57
								<td class="col-md-8">{{rel.code}}</td>
58
								<td class="col-md-4">{{rel.type}}</td>
59
								<td class="col-md-1">
60
									<button type="button" class="btn btn-xs btn-primary" ng-click="showRelModal(term, rel)">
61
										<span class="glyphicon glyphicon-pencil"></span>
62
									</button>
63
									<button type="button" class="btn btn-xs btn-danger" ng-click="deleteRel(term, rel)">
64
										<span class="glyphicon glyphicon-trash"></span>
65
									</button>
66
								</td>
67
							</tr>
68
						</table>
69
						<button class="btn btn-xs btn-primary" type="button" ng-click="showRelModal(term, null)">
70
							<span class="glyphicon glyphicon-plus"></span>
71
						</button>
72
					</div>
73
				</div>
74
			</div>
75
		</div>
76
	</div>
77
</div>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/html/vocabularies/vocabulary-list.html
1
<div class="column col-xs-12 col-sm-12 col-md-3 col-lg-3">
2
	<form role="form" class="form-inline">
3
		<button type="button" class="btn btn-default" ng-click="selectedVocabularyIndex = null; showInfoModal()">
4
			New vocabulary <span class="glyphicon glyphicon-plus"></span>
5
		</button>
6
		<div class="form-group pull-right">
7
			<input type="text" class="form-control" ng-model="vocabularyFilter" placeholder="Filter by...">
8
		</div>
9
	</form>
10
	<br/><br/>
11
	<ul class="nav nav-pills nav-stacked">
12
		<li ng-repeat="voc in vocabularies | filter:vocabularyFilter"
13
			ng-class="{'active': (selectedVocabularyIndex != null) && (voc.id == vocabularies[selectedVocabularyIndex].id)}"
14
			ng-click="loadTerms(voc)">
15
				<a>{{voc.name}}<span class="glyphicon glyphicon-chevron-right pull-right"/></a>
16
		</li>
17
	</ul>
18
</div>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/html/vocabularies/modalTerm.html
1
<div class="modal fade" id="termModal" tabindex="-1" role="dialog" aria-labelledby="termModalLabel" aria-hidden="true">
2
	<div class="modal-dialog">
3
		<div class="modal-content">
4
			<div class="modal-header">
5
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
6
				<h4 id="termModalLabel">Term editor</h4>
7
			</div>
8
			<div class="modal-body">
9
				<form name="termForm" class="form-horizontal" role="form">
10
					<div class="form-group" ng-class="{'has-error': termForm.code.$error.unique, 'has-warning': !modalTerm.code}">
11
						<label class="col-sm-4 control-label" for="code">Code</label>
12
						<div class="col-sm-8">
13
							<input class="form-control" unique-code ng-disabled="selectedTermIndex != -1" type="text" name="code" placeholder="code" ng-model="modalTerm.code">
14
						</div>
15
					</div>
16
					<div class="form-group" ng-class="{'has-warning': !modalTerm.englishName}">
17
						<label class="col-sm-4 control-label" for="englishName">English name</label>
18
					    <div class="col-sm-8">
19
					    	<input class="form-control" unique-term type="text" name="englishName" placeholder="english name" ng-model="modalTerm.englishName">
20
					    </div>
21
					</div>
22
					<div class="form-group" ng-class="{'has-warning': !modalTerm.nativeName}">
23
						<label class="col-sm-4 control-label" for="nativeName">Native name</label>
24
						<div class="col-sm-8">
25
							<input class="form-control" type="text" name="nativeName" placeholder="native name" ng-model="modalTerm.nativeName">
26
						</div>
27
					</div>
28
					<div class="form-group" ng-class="{'has-warning': !modalTerm.encoding}">
29
						<label class="col-sm-4 control-label" for="encoding">Encoding</label>
30
						<div class="col-sm-8">
31
							<input class="form-control" type="text" name="encoding" placeholder="encoding" ng-model="modalTerm.encoding">
32
						</div>
33
					</div>
34
				</form>				
35
			</div>
36
			<div class="modal-footer">
37
				<button type="button" class="btn btn-primary" ng-disabled="(termForm.code.$error.unique)||(!modalTerm.code)||(!modalTerm.englishName)"
38
				        ng-click="editTerm()">Add to vocabulary
39
				</button>
40
			</div>
41
		</div>
42
	</div>
43
</div>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/html/vocabularies/modalInfo.html
1
<div class="modal fade" id="infoModal" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel" aria-hidden="true">
2
	<div class="modal-dialog">
3
		<div class="modal-content">
4
			<div class="modal-header">
5
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
6
				<h4 id="infoModalLabel">Vocabulary information</h4>
7
			</div>
8
			<div class="modal-body">
9
				<form name="infoForm" class="form-horizontal" role="form">
10
					<div class="form-group">
11
						<label class="col-sm-4 control-label" for="vocabularyId">Vocabulary ID &#160;<a href="isManager.do#/profile/{{modalInfo.id}}"><span class="glyphicon glyphicon-link"></span></a></label>
12
					    <div class="col-sm-8">
13
					      	<input class="form-control" ng-disabled="true" type="text" name="vocabularyId" ng-model="modalInfo.id">
14
					    </div>
15
					</div>
16
					<div class="form-group" ng-class="{'has-warning': !modalInfo.name}">
17
						<label class="col-sm-4 control-label" for="vocabularyName">Vocabulary name</label>
18
					    <div class="col-sm-8">
19
					      	<input class="form-control" ng-disabled="selectedVocabularyIndex != null" type="text" name="vocabularyName" placeholder="vocabulary name" ng-model="modalInfo.name">
20
					    </div>
21
					</div>
22
					<div class="form-group" ng-class="{'has-warning': !modalInfo.code}">
23
						<label class="col-sm-4 control-label" for="vocabularyCode">Vocabulary code</label>
24
						<div class="col-sm-8">
25
							<input class="form-control" ng-disabled="selectedVocabularyIndex != null" type="text" name="vocabularyCode" placeholder="vocabulary code" ng-model="modalInfo.code">
26
						</div>
27
					</div>
28
					<div class="form-group">
29
						<label class="col-sm-4 control-label" for="vocabularyDescription">Vocabulary description</label>
30
						<div class="col-sm-8">
31
							<textarea class="col-sm-12" rows="3" type="text" name="vocabularyDescription" placeholder="vocabulary description" ng-model="modalInfo.description"></textarea>
32
						</div>
33
					</div>
34
				</form>				
35
			</div>
36
			<div class="modal-footer">
37
				<button type="button" class="btn btn-primary" ng-disabled="(!modalInfo.name)||(!modalInfo.code)" ng-click="editInfo()">Save</button>
38
			</div>
39
		</div>
40
	</div>
41
</div>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/html/vocabularies/modalSynonym.html
1
<div class="modal fade" id="synonymModal" tabindex="-1" role="dialog" aria-labelledby="synonymModalLabel" aria-hidden="true">
2
	<div class="modal-dialog">
3
		<div class="modal-content">
4
			<div class="modal-header">
5
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
6
				<h4 id="synonymModalLabel">Synonym editor</h4>
7
			</div>
8
			<div class="modal-body">
9
				<form name="synonymForm" class="form-horizontal" role="form">
10
					<div class="form-group">
11
						<label class="col-sm-4 control-label" for="refterm">Ref. Term</label>
12
					    <div class="col-sm-8">
13
							<span id="refterm" class="form-control" type="text" disabled>{{modalSynonym.refTerm}}</span>
14
					    </div>
15
					</div>
16
					<div class="form-group" ng-class="{'has-error': synonymForm.term.$error.unique, 'has-warning': !modalSynonym.term}">
17
						<label class="col-sm-4 control-label" for="term">Term</label>
18
						<div class="col-sm-8">
19
							<input class="form-control" unique-synonym name="term" type="text" placeholder="new synonym" ng-model="modalSynonym.term">
20
						</div>
21
					</div>
22
					<div class="form-group" ng-class="{'has-warning': !modalSynonym.encoding}">
23
						<label class="col-sm-4 control-label" for="encoding">Encoding</label>
24
						<div class="col-sm-8">
25
							<input class="form-control" name="encoding" type="text" placeholder="encoding" ng-model="modalSynonym.encoding">
26
						</div>
27
					</div>
28
				</form>				
29
			</div>
30
			<div class="modal-footer">
31
				<button type="button" class="btn btn-primary" ng-disabled="(synonymForm.term.$error.unique)||(!modalSynonym.term) " ng-click="editSynonym()">Add
32
					to vocabulary
33
				</button>
34
			</div>
35
		</div>
36
	</div>
37
</div>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/html/vocabularies/modalRelation.html
1
<div class="modal fade" id="relModal" tabindex="-1" role="dialog" aria-labelledby="relModalLabel" aria-hidden="true">
2
	<div class="modal-dialog">
3
		<div class="modal-content">
4
			<div class="modal-header">
5
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
6
				<h4 id="relModalLabel">Relation editor</h4>
7
			</div>
8
			<div class="modal-body">
9
				<form name="relForm" class="form-horizontal" role="form">
10
					<div class="form-group">
11
						<label class="col-sm-4 control-label" for="refterm">Ref. Term</label>
12
					    <div class="col-sm-8">
13
							<span id="refterm" class="form-control" type="text" disabled>{{modalRel.refTerm}}</span>
14
					    </div>
15
					</div>
16
					<div class="form-group" ng-class="{'has-warning': !modalRel.code}">
17
						<label class="col-sm-4 control-label" for="term">Related term</label>
18
						<div class="col-sm-8">
19
							<select class="form-control" ng-model="modalRel.code">
20
								<option value="">-- choose related term --</option>
21
								<option value="{{term.code}}" ng-repeat="term in entries" ng-selected="term.code == modalRel.code">{{term.code}}</option>
22
							</select>								
23
						</div>
24
					</div>
25
					<div class="form-group" ng-class="{'has-warning': !modalRel.type}">
26
						<label class="col-sm-4 control-label" for="encoding">Relation type</label>
27
						<div class="col-sm-8">
28
							<select class="form-control" ng-model="modalRel.type">
29
								<option value="">-- choose relation type --</option>
30
								<option value="{{rt.id}}" ng-repeat="rt in validRelations" ng-selected="rt.id == modalRel.type">{{rt.label}}</option>
31
							</select>
32
						</div>
33
					</div>
34
				</form>				
35
			</div>
36
			<div class="modal-footer">
37
				<button type="button" class="btn btn-primary" ng-disabled="!(modalRel.type && modalRel.code) " ng-click="editRel()">Save</button>
38
			</div>
39
		</div>
40
	</div>
41
</div>
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/js/vocabularies.js
1
var module = angular.module('vocabulariesUI', ['uniqueChecker', 'modalTerm', 'modalInfo', 'modalSynonym', 'modalRelation']);
2

  
3
module.directive('vocabularyList', function(){
4
	return {
5
		restrict: 'E',
6
		templateUrl: '../resources/html/vocabularies/vocabulary-list.html'
7
	};
8
});
9

  
10
module.directive('termList', function(){
11
	return {
12
		restrict: 'E',
13
		templateUrl: '../resources/html/vocabularies/term-list.html'
14
	};
15
});
16

  
17
module.controller('vocabulariesCtrl', function ($scope, $http) {
18
	$scope.entries = [];
19
	$scope.modalSynonym = {};
20
	$scope.modalRel = {};
21
	$scope.modalTerm = {};
22
	$scope.modalInfo = {};
23
	
24
	$scope.validRelations = getValidRelations();
25

  
26
	$scope.autocommit = false;
27
	
28
	initSpinner();
29
	showSpinner();
30
	
31
	$scope.loadVocabularies = function() {
32
		$http.get('vocabularies.json')
33
		.success(
34
			function(data) {
35
				$scope.vocabularies = data;
36
				hideSpinner();
37
			})
38
		.error(
39
			function() {
40
				show_notification("error", "An error occurred while loading registered vocabulary profiles..");
41
				hideSpinner();
42
			});
43
	};
44
	
45
	$scope.loadVocabularies();
46
	
47
	/*---------LOAD TERMS---------*/
48
	$scope.loadTerms = function(vocabulary) {
49
		//		// check if same vocabulary
50
		//		if ($scope.selectedVocabularyIndex != null && vocabulary.id == $scope.vocabularies[$scope.selectedVocabularyIndex].id) {
51
		//			return;
52
		//		}
53
		// prompt for uncommitted changes
54
		if (probePermanotice() == true) {
55
			var r=confirm("Switching vocabulary means losing uncommitted changes.. Are you fine with that?");
56
			if (r == false) {
57
				return;
58
			}
59
		}
60
		//actually load terms
61
		showSpinner();
62
		$http.get('terms.json?vocabularyId=' + vocabulary.id)
63
			.success(
64
				function(data) {
65
					$scope.selectedVocabularyIndex = $scope.vocabularies.indexOf(vocabulary);
66
					$scope.entries = data;
67
					$scope.termFilter = "";
68
					hidePermanotice();
69
					hideSpinner();
70
				})
71
			.error(
72
				function() {
73
					show_notification("error","An error occurred while fetching terms of vocabulary d"+vocabulary.name);
74
					hideSpinner();
75
				});
76
	};
77
	
78
	$scope.reloadTerms = function() {
79
		$scope.loadTerms($scope.vocabularies[$scope.selectedVocabularyIndex]);
80
	};
81

  
82
	/*---------DELETE---------*/
83
	$scope.deleteTerm = function(term) {
84
		if ($scope.autocommit) {
85
			var retVal = confirm("Do you want to continue ?");
86
		}
87
		if (!$scope.autocommit || retVal == true) {
88
			var index = $scope.entries.indexOf(term);
89
			$scope.entries.splice(index, 1);
90
			if ($scope.autocommit) {
91
				$scope.commit();
92
			} else {
93
				showPermanotice("Uncommitted changes!");
94
			}
95
		}
96
	};
97

  
98
	$scope.deleteSynonym = function(term, synonym) {
99
		if ($scope.autocommit) {
100
			var retVal = confirm("Do you want to continue ?");
101
		}
102
		if (!$scope.autocommit || retVal == true) {
103
			var termIndex = $scope.entries.indexOf(term);
104
			var synonymIndex = $scope.entries[termIndex].synonyms.indexOf(synonym);
105
			$scope.entries[termIndex].synonyms.splice(synonymIndex, 1);
106
			if ($scope.autocommit) {
107
				$scope.commit();
108
			} else {
109
				showPermanotice("Uncommitted changes!");
110
			}
111
		}
112
	};
113
	
114
	$scope.deleteRel = function(term, rel) {
115
		if ($scope.autocommit) {
116
			var retVal = confirm("Do you want to continue ?");
117
		}
118
		if (!$scope.autocommit || retVal == true) {
119
			var termIndex = $scope.entries.indexOf(term);
120
			var relIndex = $scope.entries[termIndex].relations.indexOf(rel);
121
			$scope.entries[termIndex].relations.splice(relIndex, 1);
122
			if ($scope.autocommit) {
123
				$scope.commit();
124
			} else {
125
				showPermanotice("Uncommitted changes!");
126
			}
127
		}
128
	};
129

  
130
	$scope.dropVocabulary = function() {
131
		var retVal = confirm("Do you want to continue ?");
132
		if (retVal == true) {
133
			showSpinner();
134
			$http.get('dropVocabulary?vocabularyId=' + $scope.vocabularies[$scope.selectedVocabularyIndex].id)
135
				.success(
136
					function () {
137
						$scope.vocabularies.splice($scope.selectedVocabularyIndex, 1);
138
						$scope.selectedVocabularyIndex = null;
139
						show_notification("success", "Vocabulary deleted successfully!");
140
						hideSpinner();
141
					})
142
				.error(
143
					function () {
144
						hideSpinner();
145
						show_notification("error", "An error occurred while dropping vocabulary " + $scope.vocabularies[$scope.selectedVocabularyIndex].name);
146
					});
147
		}
148
	};
149

  
150
	/*---------COMMIT---------*/
151
	$scope.commit = function() {
152
		showSpinner();
153
		$http.post('commitVocabulary?vocabularyId=' + $scope.vocabularies[$scope.selectedVocabularyIndex].id, $scope.entries)
154
			.success(
155
				function() {
156
					show_notification("success", "Vocabulary successfully committed!");
157
					hideSpinner();
158
					hidePermanotice();
159
					if (!$scope.autocommit) {
160
						$scope.reloadTerms();
161
					}
162
				})
163
			.error(
164
				function() {
165
					show_notification("error", "An error occurred while saving the modifications..");
166
					showPermanotice("Uncommitted changes!");
167
					hideSpinner();
168
				});
169
	}
170
});
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/js/modalTerm.js
1
var module = angular.module('modalTerm', []);
2

  
3
module.directive('modalTerm', function() {
4
	return {
5
		restrict: 'E',
6
		templateUrl: '../resources/html/vocabularies/modalTerm.html',
7
		controller: function($scope){
8
			$scope.showTermModal = function(term) {
9
				$scope.selectedTermIndex = $scope.entries.indexOf(term);
10
				if (term != null) {
11
					// edit existing term
12
					$scope.modalTerm.englishName = term.englishName;
13
					$scope.modalTerm.nativeName = term.nativeName;
14
					$scope.modalTerm.encoding = term.encoding;
15
					$scope.modalTerm.code = term.code;
16
				} else {
17
					// edit new term
18
					$scope.modalTerm.englishName = '';
19
					$scope.modalTerm.nativeName = '';
20
					$scope.modalTerm.encoding = '';
21
					$scope.modalTerm.code = '';
22
				}
23
				$('#termModal').modal();
24
			};
25
			
26
			$scope.editTerm = function() {
27
				if ($scope.selectedTermIndex == -1) {
28
					// new term
29
					$scope.entries.push({
30
						"englishName" : $scope.modalTerm.englishName,
31
						"nativeName" : $scope.modalTerm.nativeName,
32
						"encoding" : $scope.modalTerm.encoding,
33
						"synonyms" : [],
34
						"code" : $scope.modalTerm.code
35
					});
36
				} else {
37
					// term update
38
					$scope.entries[$scope.selectedTermIndex].englishName = $scope.modalTerm.englishName;
39
					$scope.entries[$scope.selectedTermIndex].nativeName = $scope.modalTerm.nativeName;
40
					$scope.entries[$scope.selectedTermIndex].encoding = $scope.modalTerm.encoding;
41
					$scope.entries[$scope.selectedTermIndex].code = $scope.modalTerm.code;
42
				}
43
				// dismiss modal
44
				$('.modal').modal('hide');
45
				if ($scope.autocommit) {
46
					$scope.commit();
47
				} else {
48
					showPermanotice("Uncommitted changes!");
49
				}
50
			}
51
		},
52
		controllerAs: 'modalTerm'
53
	};
54
	
55
});
modules/dnet-modular-uis/trunk/src/main/resources/eu/dnetlib/web/resources/js/modalSynonym.js
1
var module = angular.module('modalSynonym', []);
2

  
3
module.directive('modalSynonym', function(){
4
	return {
5
		restrict: 'E',
6
		templateUrl: '../resources/html/vocabularies/modalSynonym.html',
7
		controller: function($scope){
8
			$scope.showSynonymModal = function(term, synonym) {
9
				$scope.selectedTermIndex = $scope.entries.indexOf(term);
10
				$scope.selectedSynonymIndex = $scope.entries[$scope.selectedTermIndex].synonyms.indexOf(synonym);
11
				if (synonym != null) {
12
					// edit existing synonym
13
					$scope.modalSynonym.refTerm = $scope.entries[$scope.selectedTermIndex].englishName;
14
					$scope.modalSynonym.term = $scope.entries[$scope.selectedTermIndex].synonyms[$scope.selectedSynonymIndex].term;
15
					$scope.modalSynonym.encoding = $scope.entries[$scope.selectedTermIndex].synonyms[$scope.selectedSynonymIndex].encoding;
16
				} else {
17
					// new synonym
18
					$scope.modalSynonym.refTerm = $scope.entries[$scope.selectedTermIndex].englishName;
19
					$scope.modalSynonym.term = '';
20
					$scope.modalSynonym.encoding = '';
21
				}
22
				$('#synonymModal').modal();
23
			};
24
			
25
			$scope.editSynonym = function() {
26
				if ($scope.selectedSynonymIndex == -1) {
27
					$scope.entries[$scope.selectedTermIndex].synonyms.push({
28
						"term" : $scope.modalSynonym.term,
29
						"encoding" : $scope.modalSynonym.encoding
30
					});
31
				} else {
32
					$scope.entries[$scope.selectedTermIndex].synonyms[$scope.selectedSynonymIndex].term = $scope.modalSynonym.term;
33
					$scope.entries[$scope.selectedTermIndex].synonyms[$scope.selectedSynonymIndex].encoding = $scope.modalSynonym.encoding;
34
				}
35
				// dismiss modal
36
				$('.modal').modal('hide');
37
				if ($scope.autocommit) {
38
					$scope.commit();
39
				} else {
40
					showPermanotice("Uncommitted changes!");
41
				}
42
			}
43
		},
44
		controllerAs: 'modalSynonym'
45
	}
46
});
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff