Commit d1dfd0d3 authored by Gerrit Hübbers's avatar Gerrit Hübbers 🃏

Merge branch '72-create-an-xml-file-element-for-wizard' into 'master'

Introduce XML file publications source widget

Closes #72

See merge request !10
parents cb33948e 3f93bd1a
......@@ -180,6 +180,8 @@
<script src="scripts/components/wizardEditor/oaiPmhLinkImporter/oaiPmhLinkImporter.controller.js"></script>
<script src="scripts/components/wizardEditor/simpleConditional/simpleConditional-directive.js"></script>
<script src="scripts/components/wizardEditor/templateImporter/templateImporter.controller.js"></script>
<script src="scripts/components/wizardEditor/unApiImporter/unApiImporter.controller.js"></script>
<script src="scripts/components/wizardEditor/xmlFileImporter/xmlFileImporter.controller.js"></script>
<script src="scripts/components/wizardEditor/selectedWizard.config.js"></script>
<script src="scripts/components/wizardEditor/customTextAngularTools.js"></script>
<script src="scripts/components/wizardEditor/element.config.js"></script>
......
......@@ -30,6 +30,12 @@ angular.module('ddaApp')
url: 'api/template/upload',
file: file
});
}
},
uploadXml: function(file){
return Upload.upload({
url: 'api/xmlFiles/upload',
file: file
});
}
};
});
......@@ -73,16 +73,27 @@ angular.module('ddaApp')
}
}
}, {
'fieldName': 'unApiImporter',
'category': 'Content Upload',
'fieldOptions': {
'displayName': 'unAPI address',
'placeholder': 'Example: http://unapi.gbv.de',
'validation': {
'pattern': '(https?)://[^\\s/$.?#].[^\\s]*'
}
}
}])
'fieldName': 'unApiImporter',
'category': 'Content Upload',
'fieldOptions': {
'displayName': 'unAPI address',
'placeholder': 'Example: http://unapi.gbv.de',
'validation': {
'pattern': '(https?)://[^\\s/$.?#].[^\\s]*'
}
}
}, {
'fieldName': 'xmlFileImporter',
'category': 'Content Upload',
'fieldOptions': {
'displayName': 'XML file upload',
'placeholder': 'Select XML file',
'validation': {
'pattern': '201',
'required': true
}
}
}])
.constant('elementsWithoutUserValues', [
'simpleConditional',
'paragraph',
......
<div fg-tabs-pane="Properties">
<div fg-property-field-common="{ fieldname: true, displayname: true, tooltip: false, placeholder: true }"></div>
</div>
<div fg-tabs-pane="Validation">
<div fg-property-field-validation="{ required: true }"></div>
</div>
<div ng-controller="xmlFileImporterController">
<!-- File select -->
<div class="input-group">
<div class="input-group-btn">
<!-- TODO: Support user-defined validation messages -->
<button class="btn btn-default" type="file"
ngf-select=""
ngf-change="setData($file)"
ngf-validate="{size: {max: '5MB'}}"
ngf-validate-fn="validate($file)"
ngf-run-all-validations="true">
<i class="fa fa-folder-open"></i>
Select XML file
</button>
<button ng-if="xmlFile.name" class="btn btn-success" ng-click="uploadData()">
<i class="fa fa-upload"></i>
Upload
</button>
</div>
<input class="form-control"
fg-field-input
tabindex="{{ tabIndex }}"
placeholder="{{ field.schema.placeholder }}"
ng-model="xmlFile.name"
ng-required="field.schema.validation.required"
readonly>
</div>
<dl ng-if="form.data[field.schema.name].id" class="dl-horizontal">
<dt>Name</dt>
<dd>{{ form.data[field.schema.name].name }}</dd>
<dt>Size</dt>
<dd>{{ (form.data[field.schema.name].size / 1024).toFixed(2) }} KB</dd>
</dl>
</div>
'use strict';
angular.module('ddaApp').controller('xmlFileImporterController', function ($scope, $state, DataUtils, UploadService) {
$scope.xmlFile = {};
$scope.upload = {
loading: false,
start: false
};
var formName = $scope.field.schema.name;
$scope.setData = function (file) {
$scope.xmlFile = file;
};
$scope.validate = function (file) {
clearValidationMessages();
$scope.form.data[formName] = {};
$scope.field.state.$setDirty(true);
if (file.$errorMessages && file.$errorMessages.maxSize) {
$scope.field.state.$setValidity('templateUploadMaxSize', false);
}
if (file.$errorMessages && file.$errorMessages.pattern) {
$scope.field.state.$setValidity('templateUploadWrongType', false);
}
$scope.field.state.$setValidity('templateChanged', false);
};
$scope.uploadData = function () {
$scope.uploading = UploadService.uploadXml($scope.xmlFile);
$scope.uploading.progress(function (evt) {
$scope.upload = UploadService.mapEvent(evt);
}).success(onSaveSuccess).error(onSaveError);
};
var clearValidationMessages = function () {
$scope.field.state.$setValidity('templateUploadNoFile', true);
$scope.field.state.$setValidity('templateUploadWrongType', true);
$scope.field.state.$setValidity('templateUploadNotValid', true);
$scope.field.state.$setValidity('templateUploadMaxSize', true);
$scope.field.state.$setValidity('templateChanged', true);
};
var onSaveSuccess = function (data, status, headers, config) {
clearValidationMessages();
$scope.form.data[formName] = {
'id': data.id,
'name': data.name,
'lastModifiedDate': $scope.xmlFile.lastModifiedDate,
'size': $scope.xmlFile.size
};
};
var onSaveError = function (data, status, headers, config) {
var errorKey = headers('X-ddaApp-error-key');
$scope.field.state.$setValidity(errorKey, false);
$scope.form.data[formName] = {};
};
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment