You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by ma...@apache.org on 2016/08/29 15:32:30 UTC
syncope git commit: [SYNCOPE-854] show file preview for binary
attributes
Repository: syncope
Updated Branches:
refs/heads/master 715820744 -> 451f89bf7
[SYNCOPE-854] show file preview for binary attributes
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/451f89bf
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/451f89bf
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/451f89bf
Branch: refs/heads/master
Commit: 451f89bf761c39a174e1899963d433c27d5fb6ae
Parents: 7158207
Author: Matteo Di Carlo <ma...@tirasa.net>
Authored: Mon Aug 29 17:32:00 2016 +0200
Committer: Matteo Di Carlo <ma...@tirasa.net>
Committed: Mon Aug 29 17:32:00 2016 +0200
----------------------------------------------------------------------
client/enduser/pom.xml | 4 ++
.../resources/META-INF/resources/app/index.html | 3 ++
.../app/js/directives/dynamicPlainAttribute.js | 19 ++++---
.../resources/app/js/directives/fileInput.js | 55 ++++++++++++++++++++
.../app/views/dynamicPlainAttribute.html | 23 ++++----
pom.xml | 8 +++
6 files changed, 89 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/451f89bf/client/enduser/pom.xml
----------------------------------------------------------------------
diff --git a/client/enduser/pom.xml b/client/enduser/pom.xml
index 2ce8aa7..9b655f0 100644
--- a/client/enduser/pom.xml
+++ b/client/enduser/pom.xml
@@ -99,6 +99,10 @@ under the License.
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
+ <artifactId>bootstrap-fileinput</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.webjars.bower</groupId>
<artifactId>ng-password-strength</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/syncope/blob/451f89bf/client/enduser/src/main/resources/META-INF/resources/app/index.html
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/index.html b/client/enduser/src/main/resources/META-INF/resources/app/index.html
index 7f0271f..457cb76 100644
--- a/client/enduser/src/main/resources/META-INF/resources/app/index.html
+++ b/client/enduser/src/main/resources/META-INF/resources/app/index.html
@@ -80,6 +80,8 @@ under the License.
<script src="../webjars/angular-translate/${angular-translate.version}/angular-translate.js"></script>
<script src="../webjars/angular-translate-loader-partial/${angular-translate.version}/angular-translate-loader-partial.js"></script>
<script src="../webjars/angular-translate-storage-cookie/${angular-translate.version}/angular-translate-storage-cookie.js"></script>
+ <script src="../webjars/bootstrap-fileinput/${bootstrap-fileinput.version}/js/fileinput.js"></script>
+
<!--main angular application-->
<script src="js/app.js"></script>
<!--services-->
@@ -113,6 +115,7 @@ under the License.
<script src="js/directives/auxClasses.js"></script>
<script src="js/directives/validate.js"></script>
<script src="js/directives/validationMessage.js"></script>
+ <script src="js/directives/fileInput.js"></script>
<!--validator-->
<script src="js/validator/validationRules.js"></script>
<script src="js/validator/validationExecutor.js"></script>
http://git-wip-us.apache.org/repos/asf/syncope/blob/451f89bf/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
index 0b9526c..40d9fad 100644
--- a/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
+++ b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js
@@ -18,7 +18,6 @@
*/
'use strict';
-
angular.module('self')
.directive('dynamicPlainAttribute', function ($filter) {
return {
@@ -39,8 +38,9 @@ angular.module('self')
break;
case "Enum":
$scope.enumerationValues = [];
+
//SYNCOPE-911 empty value option on non required attributes
- if(schema.mandatoryCondition != "true"){
+ if (schema.mandatoryCondition !== "true") {
$scope.enumerationValues.push("");
}
var enumerationValuesSplitted = schema.enumerationValues.toString().split(";");
@@ -50,6 +50,7 @@ angular.module('self')
$scope.user.plainAttrs[schema.key].values[index] = $scope.user.plainAttrs[schema.key].values[index]
|| $scope.enumerationValues[0];
break;
+
case "Binary":
$scope.userFile = $scope.userFile || '';
$element.bind("change", function (changeEvent) {
@@ -67,22 +68,20 @@ angular.module('self')
$scope.download = function () {
var byteString = atob($scope.user.plainAttrs[schema.key].values[index]);
-
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
-
var blob = new Blob([ia], {type: schema.mimeType});
-
saveAs(blob, schema.key);
};
- $scope.remove = function () {
+
+ //file upload and preview
+ $('#fileInput').on('fileclear', function () {
$scope.user.plainAttrs[schema.key].values.splice(index, 1);
- $scope.userFile = '';
- $("#fileInput").replaceWith($("#fileInput").clone(true));
- };
+ });
+ $scope.previewImg = $scope.user.plainAttrs[schema.key].values[index];
break;
case "Date":
@@ -189,7 +188,7 @@ angular.module('self')
case "Boolean":
$scope.user.plainAttrs[schema.key].values[index] =
- $scope.user.plainAttrs[schema.key].values[index] == "true" ? true : false;
+ $scope.user.plainAttrs[schema.key].values[index] === "true" ? true : false;
break;
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/451f89bf/client/enduser/src/main/resources/META-INF/resources/app/js/directives/fileInput.js
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/directives/fileInput.js b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/fileInput.js
new file mode 100644
index 0000000..130a2e4
--- /dev/null
+++ b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/fileInput.js
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+'use strict';
+angular.module('self')
+ .directive('fileInput', function () {
+ return {
+ restrict: 'A',
+ link: function ($scope, element, attrs) {
+ var previewImgComposite;
+ if ($scope.previewImg) {
+ previewImgComposite = "data:image/png;base64," + $scope.previewImg;
+ } else
+ previewImgComposite = null;
+ $(element).fileinput({
+ showUpload: false,
+ showCaption: false,
+ showCancel: false,
+ showClose: true,
+ showRemove: false,
+ fileActionSettings: {'showZoom': false, indicatorNew: '', 'removeTitle': 'boh'},
+ removeClass: "btn btn-default",
+ browseClass: "btn btn-default",
+ browseLabel: '',
+ dragIcon: '',
+ browseIcon: '',
+ initialPreviewAsData: true,
+ overwriteInitial: true,
+// maxFileCount: 1,
+// 'previewFileType': 'any',
+ initialPreview: [
+ previewImgComposite
+ ],
+ 'maxFileSize': 5120
+ });
+ }
+ };
+ });
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/syncope/blob/451f89bf/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html b/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html
index 5195a30..654c0de 100644
--- a/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html
+++ b/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html
@@ -72,22 +72,19 @@ under the License.
</div>
<div ng-switch-when="Binary" ng-init="initAttribute(schema, index)">
- <!--<div enctype="multipart/form-data" accept-charset="UTF-8">-->
- <div >
- <input id="fileInput" type="file" ng-required="{{schema.mandatoryCondition}}"/>
- <button type="button" title="Download file" class="fileButton btn btn-default btn-sm" ng-click="download()">
- <i class="glyphicon glyphicon-download" ></i>
- </button>
- <button type="button" class="fileButton btn btn-default btn-sm" title="Remove file" ng-click="remove()">
- <i class="glyphicon glyphicon-remove-sign" ></i>
- </button>
- <h4><span class="label label-primary" ng-model="userFile">{{userFile}}</span></h4>
- </div>
-
+ <input file-input type="file" id="fileInput" name="fileInput">
+ <button type="button" title="Download file" class="fileButton btn btn-default btn-sm" ng-click="download()">
+ <i class="glyphicon glyphicon-download" ></i>
+ </button>
</div>
+
<input ng-switch-default class="form-control" type="text"
ng-model="user.plainAttrs[schema.key].values[index]"
ng-required="{{schema.mandatoryCondition}}"
ng-disabled="schema.readonly" ng-init="initAttribute(schema, index)"/>
-
</div>
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/syncope/blob/451f89bf/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9bc153e..73ebfe8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -420,6 +420,7 @@ under the License.
<angular-ui-select.version>0.17.1</angular-ui-select.version>
<angular-treasure-overlay-spinner.version>1.1.0</angular-treasure-overlay-spinner.version>
<angular-translate.version>2.11.1</angular-translate.version>
+ <bootstrap-fileinput.version>4.3.4</bootstrap-fileinput.version>
<ng-password-strength.version>0.2.1</ng-password-strength.version>
<lodash.version>4.15.0</lodash.version>
@@ -1218,6 +1219,13 @@ under the License.
<artifactId>angular-translate-storage-cookie</artifactId>
<version>${angular-translate.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.webjars.bower</groupId>
+ <artifactId>bootstrap-fileinput</artifactId>
+ <version>${bootstrap-fileinput.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>ng-password-strength</artifactId>