Skip to content

Commit

Permalink
fix: New project structure + better types
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciolauffer committed Apr 25, 2022
1 parent adeb2d0 commit d1993d2
Show file tree
Hide file tree
Showing 36 changed files with 7,393 additions and 1,131 deletions.
11 changes: 5 additions & 6 deletions demo/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Mauricio Lauffer">
<meta http-equiv="Content-Security-Policy"
content=" default-src 'self' https://openui5.hana.ondemand.com;
style-src 'self' 'unsafe-inline' https://openui5.hana.ondemand.com;
content="default-src 'self' https://openui5.hana.ondemand.com;
script-src 'self' 'unsafe-eval' https://openui5.hana.ondemand.com">
<title>OpenUI5 Validator</title>
</head>
<body class="sapUiBody">
<div id="content" data-sap-ui-component data-async="true" data-manifest="true"
data-id="mlauffer.demo" data-name="mlauffer.demo.openui5.validator"></div>
<div id="content" data-sap-ui-component data-async="true" data-id="mlauffer.demo"
data-name="mlauffer.demo.openui5.validator"></div>
<script id="sap-ui-bootstrap" async defer
src="https://openui5.hana.ondemand.com/1.61.2/resources/sap-ui-core.js"
src="https://openui5.hana.ondemand.com/1.100.0/resources/sap-ui-core.js"
data-sap-ui-compatVersion="edge" data-sap-ui-async="true"
data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
data-sap-ui-language="en"
data-sap-ui-xx-waitForTheme="true"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-resourceroots='{
"mlauffer.demo.openui5.validator": "./",
"openui5.validator": "../../dist/resources/openui5/validator"}'></script>
Expand Down
4 changes: 0 additions & 4 deletions dist/resources/openui5/validator/.library
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
<dependency>
<libraryName>sap.ui.core</libraryName>
</dependency>
<dependency>
<libraryName>sap.m</libraryName>
<lazy>true</lazy>
</dependency>
</dependencies>
<appData></appData>
</library>
74 changes: 37 additions & 37 deletions dist/resources/openui5/validator/Validator-dbg.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
'use strict';

/*
* openui5-validator
* (c) Copyright 2017-2021 Mauricio Lauffer
* (c) Copyright 2017-2022 Mauricio Lauffer
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/

sap.ui.define([
'sap/ui/base/Object',
'sap/ui/core/library',
'sap/ui/core/Control',
'sap/ui/core/ValueState',
'sap/ui/core/MessageType',
'sap/ui/core/message/Message',
'openui5/validator/thirdparty/ajv.min'
//'ajv/dist/ajv.min'
],
/**
* Module Dependencies
*
* @param {typeof sap.ui.base.Object} UI5Object UI5 Object
* @param {typeof sap.ui.core.Control} UI5Control UI5 Control
* @param {typeof sap.ui.core.ValueState} ValueState Value State
* @param {typeof sap.ui.core.MessageType} MessageType Messate Type
* @param {typeof sap.ui.core.message.Message} Message UI5 Message object
* @returns {object} Validator object, an extended UI5 Object
* @param {sap.ui.base.Object} UI5Object sap.ui.base.Object
* @param {sap.ui.core} coreLibrary sap.ui.core.library
* @param {sap.ui.core.Control} UI5Control sap.ui.core.Control
* @param {sap.ui.core.message.Message} Message sap.ui.core.message.Message
* @returns {object} openui5.validator.Validator
*/
function(UI5Object, UI5Control, ValueState, MessageType, Message) {
'use strict';

function(UI5Object, coreLibrary, UI5Control, Message) {
/**
* A list of properties of UI5 Controls which will be used to dynamically get the field value.
* Validation is dynamic, it neither knows the control's type nor the property which is being validated.
Expand Down Expand Up @@ -53,7 +52,6 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
*
* @author Mauricio Lauffer
* @version 0.1.18
*
* @class
* @namespace
* @name openui5.validator
Expand All @@ -63,10 +61,10 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
const Validator = UI5Object.extend('openui5.validator.Validator', {
/**
* Constructor for a new Validator.
* @extends sap.ui.base.Object
*
* @constructor
* @param {typeof sap.ui.core.mvc.View} view UI5 view which contains the fields to be validated.
* @augments sap.ui.base.Object
* @constructs
* @param {sap.ui.core.mvc.View} view UI5 view which contains the fields to be validated.
* @param {object} schema Schema used for validation.
* @param {object} opt Parameters to initialize Ajv.
* @public
Expand All @@ -83,6 +81,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
this._view = view;
this._errors = null;
this._payload = null;
/** @type {string[]} */
this._validProperties = [];
this.addValidProperties(VALID_UI5_CONTROL_PROPERTIES);
}
Expand Down Expand Up @@ -119,7 +118,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Returns all validation errors.
*
* @returns {typeof sap.ui.core.message.Message[]} Array of sap.ui.core.message.Message objects.
* @returns {sap.ui.core.message.Message[]} Array of sap.ui.core.message.Message objects.
* @public
*/
Validator.prototype.getErrors = function() {
Expand All @@ -139,7 +138,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Returns all valid properties which will be used to dynamically get the field value.
*
* @returns {array} Array with all valid properties.
* @returns {string[]} Array with all valid properties.
* @public
*/
Validator.prototype.getValidProperties = function() {
Expand All @@ -151,7 +150,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Adds new valid properties to be used to dynamically get the field value.
*
* @param {array} validProperties An array containing valid properties to be added to the class.
* @param {string[]} validProperties An array containing valid properties to be added to the class.
* @public
*/
Validator.prototype.addValidProperties = function(validProperties) {
Expand All @@ -164,7 +163,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Returns all UI5 Controls which will be validated.
*
* @returns {array} List of UI5 Controls to be validated.
* @returns {sap.ui.core.Control[]} List of UI5 Controls to be validated.
* @private
*/
Validator.prototype._getControls = function() {
Expand All @@ -186,7 +185,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Returns the payload to be validated.
*
* @param {typeof sap.ui.core.Control[]} controls List of UI5 Controls to be validated.
* @param {sap.ui.core.Control[]} controls List of UI5 Controls to be validated.
* @returns {object} Payload to be validated.
* @private
*/
Expand All @@ -204,24 +203,25 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Returns the property value of the control.
*
* @param {typeof sap.ui.core.Control} control The control which will have its value extracted.
* @param {sap.ui.core.Control} control The control which will have its value extracted.
* @returns {string} The property value of the control.
* @private
*/
Validator.prototype._getControlValue = function(control) {
let value = null;
let value = '';
const controlProperties = Object.keys(control.mProperties);
this._validProperties.forEach(function _filterControlProperties(validProperty) {
if (!value) {
const isValidProperty = controlProperties.find(function _findValidProperty(controlProperty) {
return (controlProperty === validProperty);
});
if (isValidProperty) {
/** Could use control.getProperty(property), but UI5 documentation says:
* Note: This method is a low-level API as described in the class documentation.
* Applications or frameworks must not use this method to generically retrieve the value of a property.
* Use the concrete method getXYZ for property 'XYZ' instead.
* https://openui5.hana.ondemand.com/#/api/sap.ui.base.ManagedObject/methods/getProperty
/**
Could use control.getProperty(property), but UI5 documentation says:
Note: This method is a low-level API as described in the class documentation.
Applications or frameworks must not use this method to generically retrieve the value of a property.
Use the concrete method getXYZ for property 'XYZ' instead.
https://openui5.hana.ondemand.com/#/api/sap.ui.base.ManagedObject/methods/getProperty
*/
const getPropertyMethod = ['get', validProperty.substring(0, 1).toUpperCase(), validProperty.substring(1)].join('');
if (control[getPropertyMethod]) {
Expand All @@ -236,13 +236,13 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Clears the status set to a list of controls
*
* @param {typeof sap.ui.core.Control[]} controls The controls which will have the status cleared.
* @param {sap.ui.core.Control[]} controls The controls which will have the status cleared.
* @private
*/
Validator.prototype._clearControlStatus = function(controls) {
controls.forEach(function _setValueState(control) {
if (control && control.setValueState) {
control.setValueState(ValueState.None);
control.setValueState(coreLibrary.ValueState.None);
}
if (control && control.setValueStateText) {
control.setValueStateText();
Expand All @@ -253,13 +253,13 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Sets error status and error message to a control
*
* @param {typeof sap.ui.core.Control} control The control which will have the status updated.
* @param {sap.ui.core.Control} control The control which will have the status updated.
* @param {string} message The error message to be assigned to the control.
* @private
*/
Validator.prototype._setControlErrorStatus = function(control, message) {
if (control && control.setValueState) {
control.setValueState(ValueState.Error);
control.setValueState(coreLibrary.ValueState.Error);
}
if (control && control.setValueStateText) {
control.setValueStateText(message);
Expand All @@ -269,14 +269,14 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Process all validation errors.
*
* @param {array} errors A list with all errors returned by the validation.
* @returns {typeof sap.ui.core.message.Message[]} A list of sap.ui.core.message.Message objects.
* @param {object[]} errors A list with all errors returned by the validation.
* @returns {sap.ui.core.message.Message[]} A list of sap.ui.core.message.Message objects.
* @private
*/
Validator.prototype._processValidationErrors = function(errors) {
const that = this;
/**
* @type {typeof sap.ui.core.message.Message[]}
* @type {sap.ui.core.message.Message[]}
*/
const errorMessageObjects = [];
errors.forEach(function _mapErrors(err) {
Expand All @@ -293,7 +293,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
/**
* Creates an UI5 error message object.
*
* @param {typeof sap.ui.core.Control} control The control with invalid value.
* @param {sap.ui.core.Control} control The control with invalid value.
* @param {string} shortMessage The short error message to be displayed.
* @param {string} longMessage The long error message to be displayed.
* @returns {sap.ui.core.message.Message} The UI5 error message object.
Expand All @@ -303,7 +303,7 @@ function(UI5Object, UI5Control, ValueState, MessageType, Message) {
return new Message({
message: shortMessage,
description: longMessage,
type: MessageType.Error,
type: coreLibrary.MessageType.Error,
target: [control.getId(), '/'].join('')
});
};
Expand Down
6 changes: 3 additions & 3 deletions dist/resources/openui5/validator/Validator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions dist/resources/openui5/validator/library-dbg.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
'use strict';

/* !
* openui5-validator
* (c) Copyright 2017-2021 Mauricio Lauffer
* (c) Copyright 2017-2022 Mauricio Lauffer
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/

sap.ui.define([
'sap/ui/core/Core',
'sap/ui/core/library'
], function() {
'use strict';

],
/**
* Module Dependencies
*
* @param {sap.ui.core.Core} Core - sap.ui.core.Core
* @returns {any} openui5.validator
*/
function(Core) {
/**
* OpenUI5 library: openui5.validator.
*
Expand All @@ -18,7 +26,7 @@ sap.ui.define([
* @version 0.1.18
* @public
*/
return sap.ui.getCore().initLibrary({
return Core.initLibrary({
name: 'openui5.validator',
dependencies: [
'sap.ui.core'
Expand Down
Loading

0 comments on commit d1993d2

Please sign in to comment.