diff --git a/docs-core/src/main/java/com/sismics/docs/core/util/MetadataUtil.java b/docs-core/src/main/java/com/sismics/docs/core/util/MetadataUtil.java
index b24b7dd1..9a4ee5b9 100644
--- a/docs-core/src/main/java/com/sismics/docs/core/util/MetadataUtil.java
+++ b/docs-core/src/main/java/com/sismics/docs/core/util/MetadataUtil.java
@@ -9,7 +9,6 @@ import com.sismics.docs.core.dao.dto.DocumentMetadataDto;
import com.sismics.docs.core.dao.dto.MetadataDto;
import com.sismics.docs.core.model.jpa.DocumentMetadata;
import com.sismics.docs.core.util.jpa.SortCriteria;
-import com.sismics.util.JsonUtil;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
@@ -105,7 +104,7 @@ public class MetadataUtil {
break;
case FLOAT:
try {
- Float.parseFloat(value);
+ Double.parseDouble(value);
} catch (NumberFormatException e) {
throw new Exception("Float value not parsable");
}
@@ -169,7 +168,25 @@ public class MetadataUtil {
.add("type", metadataDto.getType().name());
for (DocumentMetadataDto documentMetadataDto : documentMetadataDtoList) {
if (documentMetadataDto.getMetadataId().equals(metadataDto.getId())) {
- meta.add("value", JsonUtil.nullable(documentMetadataDto.getValue()));
+ if (documentMetadataDto.getValue() != null) {
+ switch (metadataDto.getType()) {
+ case STRING:
+ meta.add("value", documentMetadataDto.getValue());
+ break;
+ case BOOLEAN:
+ meta.add("value", Boolean.parseBoolean(documentMetadataDto.getValue()));
+ break;
+ case DATE:
+ meta.add("value", Long.parseLong(documentMetadataDto.getValue()));
+ break;
+ case FLOAT:
+ meta.add("value", Double.parseDouble(documentMetadataDto.getValue()));
+ break;
+ case INTEGER:
+ meta.add("value", Integer.parseInt(documentMetadataDto.getValue()));
+ break;
+ }
+ }
}
}
metadata.add(meta);
diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/MetadataResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/MetadataResource.java
index 5dac5f54..be271747 100644
--- a/docs-web/src/main/java/com/sismics/docs/rest/resource/MetadataResource.java
+++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/MetadataResource.java
@@ -37,7 +37,7 @@ public class MetadataResource extends BaseResource {
* @apiSuccess {String} metadata.name Name
* @apiSuccess {String="STRING","INTEGER","FLOAT","DATE","BOOLEAN"} metadata.type Type
* @apiError (client) ForbiddenError Access denied
- * @apiPermission admin
+ * @apiPermission user
* @apiVersion 1.7.0
*
* @return Response
diff --git a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js
index 3d979f1e..c7f4fd02 100644
--- a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js
+++ b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js
@@ -59,9 +59,18 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
$scope.document = {
tags: [],
relations: [],
- language: language
+ language: language,
+ metadata: []
};
+ // Get custom metadata list
+ Restangular.one('metadata').get({
+ sort_column: 1,
+ asc: true
+ }).then(function(data) {
+ $scope.document.metadata = data.metadata;
+ });
+
if ($scope.navigatedTag) {
$scope.document.tags.push($scope.navigatedTag);
}
@@ -92,7 +101,21 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
// Extract ids from relations (only when our document is the source)
document.relations = _.pluck(_.where(document.relations, { source: true }), 'id');
-
+
+ // Extract custom metadata values
+ var metadata = _.reject(document.metadata, function (meta) {
+ return _.isUndefined(meta.value) || meta.value === '' || meta.value == null;
+ });
+ document.metadata_id = _.pluck(metadata, 'id');
+ document.metadata_value = _.pluck(metadata, 'value');
+ document.metadata_value = _.map(document.metadata_value, function (val) {
+ if (val instanceof Date) {
+ return val.getTime();
+ }
+ return val;
+ });
+
+ // Send to server
if ($scope.isEdit()) {
promise = Restangular.one('document', $stateParams.id).post('', document);
} else {
diff --git a/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsMetadata.js b/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsMetadata.js
index b8170cfd..6fa7d4fb 100644
--- a/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsMetadata.js
+++ b/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsMetadata.js
@@ -5,7 +5,10 @@
*/
angular.module('docs').controller('SettingsMetadata', function($scope, Restangular) {
// Load metadata
- Restangular.one('metadata').get().then(function(data) {
+ Restangular.one('metadata').get({
+ sort_column: 1,
+ asc: true
+ }).then(function(data) {
$scope.metadata = data.metadata;
});
diff --git a/docs-web/src/main/webapp/src/locale/en.json b/docs-web/src/main/webapp/src/locale/en.json
index 6dd8432f..efc52757 100644
--- a/docs-web/src/main/webapp/src/locale/en.json
+++ b/docs-web/src/main/webapp/src/locale/en.json
@@ -597,6 +597,8 @@
"description": "Documents can be organized in tags (which are like super-folders). Create them here."
}
},
+ "yes": "Yes",
+ "no": "No",
"ok": "OK",
"cancel": "Cancel",
"share": "Share",
diff --git a/docs-web/src/main/webapp/src/locale/fr.json b/docs-web/src/main/webapp/src/locale/fr.json
index 932f287f..3aa7f78d 100644
--- a/docs-web/src/main/webapp/src/locale/fr.json
+++ b/docs-web/src/main/webapp/src/locale/fr.json
@@ -586,6 +586,8 @@
"description": "Les documents peuvent être organisés en tags (qui sont comme des super-dossiers). Créez-les ici."
}
},
+ "yes": "Oui",
+ "no": "Non",
"ok": "OK",
"cancel": "Annuler",
"share": "Partager",
diff --git a/docs-web/src/main/webapp/src/partial/docs/document.edit.html b/docs-web/src/main/webapp/src/partial/docs/document.edit.html
index 7363dc99..ef59e412 100644
--- a/docs-web/src/main/webapp/src/partial/docs/document.edit.html
+++ b/docs-web/src/main/webapp/src/partial/docs/document.edit.html
@@ -44,7 +44,7 @@
clear-text="{{ 'directive.datepicker.clear' | translate }}"
close-text="{{ 'directive.datepicker.close' | translate }}"
ng-readonly="true" uib-datepicker-popup="{{ dateFormat }}" class="form-control"
- ng-model="document.create_date" datepicker-options="{ startingDay:1, showWeeks: false }"
+ ng-model="document.create_date" datepicker-options="{ startingDay: 1, showWeeks: false }"
ng-click="datepickerOpened = true" is-open="datepickerOpened" ng-disabled="fileIsUploading" />
@@ -72,6 +72,42 @@