From d95c93bbc25d1f16b9ef99f3e09a55889121e22d Mon Sep 17 00:00:00 2001 From: HerrHase Date: Sun, 29 Aug 2021 23:49:56 +0200 Subject: [PATCH] adding --- public/js/bucket-single.js | 52 +++++++--- public/js/create-bucket.js | 14 +-- public/js/dashboard.js | 28 ++--- public/js/users.js | 124 ++++++++++++++++------- resources/js/FormValidator.js | 18 ++++ resources/js/components/field-error.riot | 2 +- resources/js/components/loading.riot | 0 resources/js/components/users.riot | 7 ++ resources/js/components/users/form.riot | 26 ++++- src/http/api/users.ts | 3 +- 10 files changed, 191 insertions(+), 83 deletions(-) create mode 100644 resources/js/components/loading.riot diff --git a/public/js/bucket-single.js b/public/js/bucket-single.js index cf2214e..90804ef 100644 --- a/public/js/bucket-single.js +++ b/public/js/bucket-single.js @@ -52,7 +52,7 @@ __webpack_require__.r(__webpack_exports__); const parent = this.root.closest(state.closest) // getting current element by name - const element = document.querySelector('[name="' + props.name + '"]') + const element = parent.querySelector('[name="' + props.name + '"]') // getting form const form = element.closest('form') @@ -124,7 +124,7 @@ __webpack_require__.r(__webpack_exports__); getComponent ) { return template( - '
', + '
', [ { 'type': bindingTypes.IF, @@ -135,11 +135,11 @@ __webpack_require__.r(__webpack_exports__); return _scope.state.errors.length > 0; }, - 'redundantAttribute': 'expr15', - 'selector': '[expr15]', + 'redundantAttribute': 'expr3', + 'selector': '[expr3]', 'template': template( - '', + '', [ { 'type': bindingTypes.EACH, @@ -170,8 +170,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr16', - 'selector': '[expr16]', + 'redundantAttribute': 'expr4', + 'selector': '[expr4]', 'itemName': 'error', 'indexName': null, @@ -289,7 +289,7 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') getComponent ) { return template( - '
', + '
', [ { 'type': bindingTypes.IF, @@ -300,8 +300,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') return _scope.state.note && _scope.state.note._id; }, - 'redundantAttribute': 'expr17', - 'selector': '[expr17]', + 'redundantAttribute': 'expr0', + 'selector': '[expr0]', 'template': template( null, @@ -332,8 +332,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') return !_scope.state.note || (_scope.state.note && !_scope.state.note._id); }, - 'redundantAttribute': 'expr18', - 'selector': '[expr18]', + 'redundantAttribute': 'expr1', + 'selector': '[expr1]', 'template': template( '\n Create\n ', @@ -349,8 +349,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') return _scope.state.note && _scope.state.note._id; }, - 'redundantAttribute': 'expr19', - 'selector': '[expr19]', + 'redundantAttribute': 'expr2', + 'selector': '[expr2]', 'template': template( '\n Save\n ', @@ -2265,12 +2265,32 @@ var FormValidator = /*#__PURE__*/function () { } /** * - * @param {[type]} event [description] - * @return {[type]} [description] + * */ _createClass(FormValidator, [{ + key: "setConstraits", + value: function setConstraits(constraits) { + this.constraits = constraits; + } + /** + * + * + */ + + }, { + key: "getConstraits", + value: function getConstraits(constraits) { + return this.constraits; + } + /** + * + * @param {[type]} event [description] + * @return {[type]} [description] + */ + + }, { key: "onSubmit", value: function onSubmit(event) { var _this2 = this; diff --git a/public/js/create-bucket.js b/public/js/create-bucket.js index 96a557f..d285795 100644 --- a/public/js/create-bucket.js +++ b/public/js/create-bucket.js @@ -52,7 +52,7 @@ __webpack_require__.r(__webpack_exports__); const parent = this.root.closest(state.closest) // getting current element by name - const element = document.querySelector('[name="' + props.name + '"]') + const element = parent.querySelector('[name="' + props.name + '"]') // getting form const form = element.closest('form') @@ -124,7 +124,7 @@ __webpack_require__.r(__webpack_exports__); getComponent ) { return template( - '
', + '
', [ { 'type': bindingTypes.IF, @@ -135,11 +135,11 @@ __webpack_require__.r(__webpack_exports__); return _scope.state.errors.length > 0; }, - 'redundantAttribute': 'expr15', - 'selector': '[expr15]', + 'redundantAttribute': 'expr3', + 'selector': '[expr3]', 'template': template( - '', + '', [ { 'type': bindingTypes.EACH, @@ -170,8 +170,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr16', - 'selector': '[expr16]', + 'redundantAttribute': 'expr4', + 'selector': '[expr4]', 'itemName': 'error', 'indexName': null, diff --git a/public/js/dashboard.js b/public/js/dashboard.js index cddfd33..61dbd1a 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -74,7 +74,7 @@ __webpack_require__.r(__webpack_exports__); getComponent ) { return template( - '
', + '
', [ { 'type': bindingTypes.EACH, @@ -82,11 +82,11 @@ __webpack_require__.r(__webpack_exports__); 'condition': null, 'template': template( - '
', + '
', [ { - 'redundantAttribute': 'expr1', - 'selector': '[expr1]', + 'redundantAttribute': 'expr17', + 'selector': '[expr17]', 'expressions': [ { @@ -102,8 +102,8 @@ __webpack_require__.r(__webpack_exports__); ] }, { - 'redundantAttribute': 'expr2', - 'selector': '[expr2]', + 'redundantAttribute': 'expr18', + 'selector': '[expr18]', 'expressions': [ { @@ -124,8 +124,8 @@ __webpack_require__.r(__webpack_exports__); ] }, { - 'redundantAttribute': 'expr3', - 'selector': '[expr3]', + 'redundantAttribute': 'expr19', + 'selector': '[expr19]', 'expressions': [ { @@ -145,8 +145,8 @@ __webpack_require__.r(__webpack_exports__); ] }, { - 'redundantAttribute': 'expr4', - 'selector': '[expr4]', + 'redundantAttribute': 'expr20', + 'selector': '[expr20]', 'expressions': [ { @@ -168,8 +168,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr0', - 'selector': '[expr0]', + 'redundantAttribute': 'expr16', + 'selector': '[expr16]', 'itemName': 'bucket', 'indexName': null, @@ -180,8 +180,8 @@ __webpack_require__.r(__webpack_exports__); } }, { - 'redundantAttribute': 'expr5', - 'selector': '[expr5]', + 'redundantAttribute': 'expr21', + 'selector': '[expr21]', 'expressions': [ { diff --git a/public/js/users.js b/public/js/users.js index e387960..d6351ab 100644 --- a/public/js/users.js +++ b/public/js/users.js @@ -52,7 +52,7 @@ __webpack_require__.r(__webpack_exports__); const parent = this.root.closest(state.closest) // getting current element by name - const element = document.querySelector('[name="' + props.name + '"]') + const element = parent.querySelector('[name="' + props.name + '"]') // getting form const form = element.closest('form') @@ -124,7 +124,7 @@ __webpack_require__.r(__webpack_exports__); getComponent ) { return template( - '
', + '
', [ { 'type': bindingTypes.IF, @@ -135,11 +135,11 @@ __webpack_require__.r(__webpack_exports__); return _scope.state.errors.length > 0; }, - 'redundantAttribute': 'expr15', - 'selector': '[expr15]', + 'redundantAttribute': 'expr3', + 'selector': '[expr3]', 'template': template( - '', + '', [ { 'type': bindingTypes.EACH, @@ -170,8 +170,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr16', - 'selector': '[expr16]', + 'redundantAttribute': 'expr4', + 'selector': '[expr4]', 'itemName': 'error', 'indexName': null, @@ -421,11 +421,11 @@ __webpack_require__.r(__webpack_exports__); getComponent ) { return template( - '', + '', [ { - 'redundantAttribute': 'expr20', - 'selector': '[expr20]', + 'redundantAttribute': 'expr14', + 'selector': '[expr14]', 'expressions': [ { @@ -444,8 +444,8 @@ __webpack_require__.r(__webpack_exports__); 'type': bindingTypes.SLOT, 'attributes': [], 'name': 'default', - 'redundantAttribute': 'expr21', - 'selector': '[expr21]' + 'redundantAttribute': 'expr15', + 'selector': '[expr15]' } ] ); @@ -495,6 +495,13 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') this.fetch() }, + /** + * + * @param {[type]} event + * @param {[type]} user + * @return {[type]} + * + */ handleUpdate(event, user) { const customEvent = new CustomEvent('app-users-form-open', { 'detail': user @@ -550,7 +557,7 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') getComponent ) { return template( - '
\n Email\n \n Display Name\n \n Roles\n
', + '
\n Email\n \n Display Name\n \n Roles\n
', [ { 'type': bindingTypes.EACH, @@ -558,11 +565,11 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') 'condition': null, 'template': template( - '
', + '
', [ { - 'redundantAttribute': 'expr7', - 'selector': '[expr7]', + 'redundantAttribute': 'expr6', + 'selector': '[expr6]', 'expressions': [ { @@ -582,8 +589,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') ] }, { - 'redundantAttribute': 'expr8', - 'selector': '[expr8]', + 'redundantAttribute': 'expr7', + 'selector': '[expr7]', 'expressions': [ { @@ -611,8 +618,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') return _scope.user.roles && _scope.user.roles.indexOf('admin') >= 0; }, - 'redundantAttribute': 'expr9', - 'selector': '[expr9]', + 'redundantAttribute': 'expr8', + 'selector': '[expr8]', 'template': template( '\n Admin\n ', @@ -650,12 +657,12 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') } ], - 'redundantAttribute': 'expr10', - 'selector': '[expr10]' + 'redundantAttribute': 'expr9', + 'selector': '[expr9]' }, { - 'redundantAttribute': 'expr11', - 'selector': '[expr11]', + 'redundantAttribute': 'expr10', + 'selector': '[expr10]', 'expressions': [ { @@ -673,8 +680,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') ] ), - 'redundantAttribute': 'expr6', - 'selector': '[expr6]', + 'redundantAttribute': 'expr5', + 'selector': '[expr5]', 'itemName': 'user', 'indexName': null, @@ -703,8 +710,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') ], 'attributes': [], - 'redundantAttribute': 'expr12', - 'selector': '[expr12]' + 'redundantAttribute': 'expr11', + 'selector': '[expr11]' }, { 'type': bindingTypes.IF, @@ -715,15 +722,15 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') return _scope.state.maxLength > _scope.state.users.length; }, - 'redundantAttribute': 'expr13', - 'selector': '[expr13]', + 'redundantAttribute': 'expr12', + 'selector': '[expr12]', 'template': template( - '
', + '
', [ { - 'redundantAttribute': 'expr14', - 'selector': '[expr14]', + 'redundantAttribute': 'expr13', + 'selector': '[expr13]', 'expressions': [ { @@ -797,12 +804,22 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') // check for data, and if user is send add to state if (event.detail.data) { this.state.user = event.detail.data + this.state.formValidation.setConstraits({ + 'email': { + 'length': { + 'maximum': 255 + }, + 'email': true, + 'presence': true + } + }) + this.update() } }) // create form validation - const formValidation = new _FormValidator__WEBPACK_IMPORTED_MODULE_1__.default('#app-users-form', { + this.state.formValidation = new _FormValidator__WEBPACK_IMPORTED_MODULE_1__.default('#app-users-form', { 'email': { 'length': { 'maximum': 255 @@ -844,18 +861,27 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') handleSubmit(event, data) { let method = 'post' + let url = '/api/users' + // user is set and has id, send as put with id if (this.state.user && this.state.user._id) { method = 'put' + url += '/' + this.state.user._id } axios__WEBPACK_IMPORTED_MODULE_0___default()({ method: method, - url: '/api/users', + url: url, data: data }).then((response) => { + this.state.user = response.data.data - this.$('#sidebar-user-form-close').click() + + console.log(event) + + if (event.submitter.attributes.close) { + this.$('#sidebar-user-form-close').click() + } this.update() }) @@ -863,7 +889,7 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') /** * - * + * */ reset() { this.state.user = { } @@ -2931,12 +2957,32 @@ var FormValidator = /*#__PURE__*/function () { } /** * - * @param {[type]} event [description] - * @return {[type]} [description] + * */ _createClass(FormValidator, [{ + key: "setConstraits", + value: function setConstraits(constraits) { + this.constraits = constraits; + } + /** + * + * + */ + + }, { + key: "getConstraits", + value: function getConstraits(constraits) { + return this.constraits; + } + /** + * + * @param {[type]} event [description] + * @return {[type]} [description] + */ + + }, { key: "onSubmit", value: function onSubmit(event) { var _this2 = this; diff --git a/resources/js/FormValidator.js b/resources/js/FormValidator.js index d5f5b7e..c26d8ee 100644 --- a/resources/js/FormValidator.js +++ b/resources/js/FormValidator.js @@ -45,6 +45,24 @@ class FormValidator this.onSuccess = onSuccess } + /** + * + * + */ + setConstraits(constraits) + { + this.constraits = constraits + } + + /** + * + * + */ + getConstraits(constraits) + { + return this.constraits + } + /** * * @param {[type]} event [description] diff --git a/resources/js/components/field-error.riot b/resources/js/components/field-error.riot index fedac8f..bf3cd3a 100644 --- a/resources/js/components/field-error.riot +++ b/resources/js/components/field-error.riot @@ -56,7 +56,7 @@ const parent = this.root.closest(state.closest) // getting current element by name - const element = document.querySelector('[name="' + props.name + '"]') + const element = parent.querySelector('[name="' + props.name + '"]') // getting form const form = element.closest('form') diff --git a/resources/js/components/loading.riot b/resources/js/components/loading.riot new file mode 100644 index 0000000..e69de29 diff --git a/resources/js/components/users.riot b/resources/js/components/users.riot index 67cefd1..24ecc78 100644 --- a/resources/js/components/users.riot +++ b/resources/js/components/users.riot @@ -104,6 +104,13 @@ this.fetch() }, + /** + * + * @param {[type]} event + * @param {[type]} user + * @return {[type]} + * + */ handleUpdate(event, user) { const customEvent = new CustomEvent('app-users-form-open', { 'detail': user diff --git a/resources/js/components/users/form.riot b/resources/js/components/users/form.riot index 33130a3..75a9908 100644 --- a/resources/js/components/users/form.riot +++ b/resources/js/components/users/form.riot @@ -107,12 +107,22 @@ // check for data, and if user is send add to state if (event.detail.data) { this.state.user = event.detail.data + this.state.formValidation.setConstraits({ + 'email': { + 'length': { + 'maximum': 255 + }, + 'email': true, + 'presence': true + } + }) + this.update() } }) // create form validation - const formValidation = new FormValidator('#app-users-form', { + this.state.formValidation = new FormValidator('#app-users-form', { 'email': { 'length': { 'maximum': 255 @@ -154,18 +164,26 @@ handleSubmit(event, data) { let method = 'post' + let url = '/api/users' + // user is set and has id, send as put with id if (this.state.user && this.state.user._id) { method = 'put' + url += '/' + this.state.user._id } axios({ method: method, - url: '/api/users', + url: url, data: data }).then((response) => { + this.state.user = response.data.data - this.$('#sidebar-user-form-close').click() + + // check if submit has close-attribute + if (event.submitter.attributes.close) { + this.$('#sidebar-user-form-close').click() + } this.update() }) @@ -173,7 +191,7 @@ /** * - * + * */ reset() { this.state.user = { } diff --git a/src/http/api/users.ts b/src/http/api/users.ts index 85b83f7..521909a 100644 --- a/src/http/api/users.ts +++ b/src/http/api/users.ts @@ -90,7 +90,7 @@ router.put('/:id', async function(request, response) const [ valid, errors ] = await validate(body, { email: [ isEmail, maxLength(255), required ], - password: [ required, maxLength(64) ] + password: [ maxLength(64) ] }) if (valid) { @@ -121,7 +121,6 @@ router.delete('/:id', async function(request, response) const userRepository = new UserRepository() // @TODO check for permission of current user - let user = false const [ valid, errors ] = await validate(request.params, {