diff --git a/public/js/bucket-single.js b/public/js/bucket-single.js index 7eda8ab..abca208 100644 --- a/public/js/bucket-single.js +++ b/public/js/bucket-single.js @@ -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': 'expr7', - 'selector': '[expr7]', + 'redundantAttribute': 'expr18', + 'selector': '[expr18]', 'template': template( - '', + '', [ { 'type': bindingTypes.EACH, @@ -170,8 +170,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr8', - 'selector': '[expr8]', + 'redundantAttribute': 'expr19', + 'selector': '[expr19]', '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': 'expr9', - 'selector': '[expr9]', + 'redundantAttribute': 'expr7', + 'selector': '[expr7]', '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': 'expr10', - 'selector': '[expr10]', + 'redundantAttribute': 'expr8', + 'selector': '[expr8]', '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': 'expr11', - 'selector': '[expr11]', + 'redundantAttribute': 'expr9', + 'selector': '[expr9]', 'template': template( '\n Save\n ', diff --git a/public/js/create-bucket.js b/public/js/create-bucket.js index defca11..b406f16 100644 --- a/public/js/create-bucket.js +++ b/public/js/create-bucket.js @@ -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': 'expr7', - 'selector': '[expr7]', + 'redundantAttribute': 'expr18', + 'selector': '[expr18]', 'template': template( - '', + '', [ { 'type': bindingTypes.EACH, @@ -170,8 +170,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr8', - 'selector': '[expr8]', + 'redundantAttribute': 'expr19', + 'selector': '[expr19]', 'itemName': 'error', 'indexName': null, diff --git a/public/js/dashboard.js b/public/js/dashboard.js index d32b926..cddfd33 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': 'expr14', - 'selector': '[expr14]', + 'redundantAttribute': 'expr1', + 'selector': '[expr1]', 'expressions': [ { @@ -102,8 +102,8 @@ __webpack_require__.r(__webpack_exports__); ] }, { - 'redundantAttribute': 'expr15', - 'selector': '[expr15]', + 'redundantAttribute': 'expr2', + 'selector': '[expr2]', 'expressions': [ { @@ -124,8 +124,8 @@ __webpack_require__.r(__webpack_exports__); ] }, { - 'redundantAttribute': 'expr16', - 'selector': '[expr16]', + 'redundantAttribute': 'expr3', + 'selector': '[expr3]', 'expressions': [ { @@ -145,8 +145,8 @@ __webpack_require__.r(__webpack_exports__); ] }, { - 'redundantAttribute': 'expr17', - 'selector': '[expr17]', + 'redundantAttribute': 'expr4', + 'selector': '[expr4]', 'expressions': [ { @@ -168,8 +168,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr13', - 'selector': '[expr13]', + 'redundantAttribute': 'expr0', + 'selector': '[expr0]', 'itemName': 'bucket', 'indexName': null, @@ -180,8 +180,8 @@ __webpack_require__.r(__webpack_exports__); } }, { - 'redundantAttribute': 'expr18', - 'selector': '[expr18]', + 'redundantAttribute': 'expr5', + 'selector': '[expr5]', 'expressions': [ { diff --git a/public/js/users.js b/public/js/users.js index 521a9f4..37cacd1 100644 --- a/public/js/users.js +++ b/public/js/users.js @@ -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': 'expr7', - 'selector': '[expr7]', + 'redundantAttribute': 'expr18', + 'selector': '[expr18]', 'template': template( - '', + '', [ { 'type': bindingTypes.EACH, @@ -170,8 +170,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr8', - 'selector': '[expr8]', + 'redundantAttribute': 'expr19', + 'selector': '[expr19]', 'itemName': 'error', 'indexName': null, @@ -193,6 +193,152 @@ __webpack_require__.r(__webpack_exports__); /***/ }), +/***/ "./resources/js/components/modal.riot": +/*!********************************************!*\ + !*** ./resources/js/components/modal.riot ***! + \********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ }); +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ + 'css': null, + + 'exports': { + state: { + confirm: {} + }, + + onMounted() { + this.root.addEventListener('open', this.__open) + this.root.addEventListener('close', this.__close) + }, + + __open(event) { + + // adding confirm function to state + this.state.confirm = event.detail.confirm + this.state.body = event.detail.body + + this.$('.modal').classList.add('modal--open') + this.update() + }, + + __close(event) { + this.$('.modal').classList.remove('modal--open') + this.update() + }, + + /** + * + * @param {[type]} event + * @return {[type]} + * + */ + handleConfirm(event) { + event.preventDefault() + + // calling confirm function + this.state.confirm() + + this.__close() + }, + + /** + * + * + * @param {object} event + * + */ + handleClose(event) { + event.preventDefault() + this.__close() + } + }, + + 'template': function( + template, + expressionTypes, + bindingTypes, + getComponent + ) { + return template( + '', + [ + { + 'type': bindingTypes.SLOT, + 'attributes': [], + 'name': 'title', + 'redundantAttribute': 'expr25', + 'selector': '[expr25]' + }, + { + 'redundantAttribute': 'expr26', + 'selector': '[expr26]', + + 'expressions': [ + { + 'type': expressionTypes.TEXT, + 'childNodeIndex': 0, + + 'evaluate': function( + _scope + ) { + return [ + _scope.state.body + ].join( + '' + ); + } + } + ] + }, + { + 'redundantAttribute': 'expr27', + 'selector': '[expr27]', + + 'expressions': [ + { + 'type': expressionTypes.EVENT, + 'name': 'onclick', + + 'evaluate': function( + _scope + ) { + return (event) => { _scope.handleConfirm(event) }; + } + } + ] + }, + { + 'redundantAttribute': 'expr28', + 'selector': '[expr28]', + + 'expressions': [ + { + 'type': expressionTypes.EVENT, + 'name': 'onclick', + + 'evaluate': function( + _scope + ) { + return (event) => { _scope.handleClose(event) }; + } + } + ] + } + ] + ); + }, + + 'name': 'app-modal' +}); + +/***/ }), + /***/ "./resources/js/components/sidebar-button.riot": /*!*****************************************************!*\ !*** ./resources/js/components/sidebar-button.riot ***! @@ -264,11 +410,11 @@ __webpack_require__.r(__webpack_exports__); getComponent ) { return template( - '', + '', [ { - 'redundantAttribute': 'expr12', - 'selector': '[expr12]', + 'redundantAttribute': 'expr6', + 'selector': '[expr6]', 'expressions': [ { @@ -307,8 +453,16 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var lodash_remove__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash.remove */ "./node_modules/lodash.remove/index.js"); /* harmony import */ var lodash_remove__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_remove__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var riot__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! riot */ "./node_modules/riot/riot.esm.js"); +/* harmony import */ var _modal_riot__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modal.riot */ "./resources/js/components/modal.riot"); + + + + +riot__WEBPACK_IMPORTED_MODULE_3__.register('app-modal', _modal_riot__WEBPACK_IMPORTED_MODULE_2__.default) +riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal') /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ 'css': null, @@ -328,18 +482,33 @@ __webpack_require__.r(__webpack_exports__); }, handleDelete(event, user) { + event.preventDefault() - axios__WEBPACK_IMPORTED_MODULE_0___default().delete('/api/users/' + user._id) - .then((response) => { + const customEvent = new CustomEvent('open', { + 'detail': { + 'confirm': () => { + axios__WEBPACK_IMPORTED_MODULE_0___default().delete('/api/users/' + user._id) + .then((response) => { - // removing from buckets - lodash_remove__WEBPACK_IMPORTED_MODULE_1___default()(this.state.users, function(u) { - return u._id === user._id - }) + // removing from buckets + lodash_remove__WEBPACK_IMPORTED_MODULE_1___default()(this.state.users, function(u) { + return u._id === user._id + }) - this.update() - }) + this.update() + }) + }, + + // @TODO find a better solution to create body text + 'body': 'Do you want delete ' + user.email + '?' + } + }); + + this.$('#user-delete-confirm').dispatchEvent(customEvent); + + /** + */ }, /** @@ -362,7 +531,7 @@ __webpack_require__.r(__webpack_exports__); 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, @@ -370,11 +539,11 @@ __webpack_require__.r(__webpack_exports__); 'condition': null, 'template': template( - '
', + '
', [ { - 'redundantAttribute': 'expr1', - 'selector': '[expr1]', + 'redundantAttribute': 'expr11', + 'selector': '[expr11]', 'expressions': [ { @@ -394,8 +563,8 @@ __webpack_require__.r(__webpack_exports__); ] }, { - 'redundantAttribute': 'expr2', - 'selector': '[expr2]', + 'redundantAttribute': 'expr12', + 'selector': '[expr12]', 'expressions': [ { @@ -423,8 +592,8 @@ __webpack_require__.r(__webpack_exports__); return _scope.user.roles && _scope.user.roles.indexOf('admin') >= 0; }, - 'redundantAttribute': 'expr3', - 'selector': '[expr3]', + 'redundantAttribute': 'expr13', + 'selector': '[expr13]', 'template': template( '\n Admin\n ', @@ -432,8 +601,8 @@ __webpack_require__.r(__webpack_exports__); ) }, { - 'redundantAttribute': 'expr4', - 'selector': '[expr4]', + 'redundantAttribute': 'expr14', + 'selector': '[expr14]', 'expressions': [ { @@ -451,8 +620,8 @@ __webpack_require__.r(__webpack_exports__); ] ), - 'redundantAttribute': 'expr0', - 'selector': '[expr0]', + 'redundantAttribute': 'expr10', + 'selector': '[expr10]', 'itemName': 'user', 'indexName': null, @@ -462,6 +631,28 @@ __webpack_require__.r(__webpack_exports__); return _scope.state.users; } }, + { + 'type': bindingTypes.TAG, + 'getComponent': getComponent, + + 'evaluate': function( + _scope + ) { + return 'app-modal'; + }, + + 'slots': [ + { + 'id': 'title', + 'html': '\n Delete\n ', + 'bindings': [] + } + ], + + 'attributes': [], + 'redundantAttribute': 'expr15', + 'selector': '[expr15]' + }, { 'type': bindingTypes.IF, @@ -471,15 +662,15 @@ __webpack_require__.r(__webpack_exports__); return _scope.state.maxLength > _scope.state.users.length; }, - 'redundantAttribute': 'expr5', - 'selector': '[expr5]', + 'redundantAttribute': 'expr16', + 'selector': '[expr16]', 'template': template( - '
', + '
', [ { - 'redundantAttribute': 'expr6', - 'selector': '[expr6]', + 'redundantAttribute': 'expr17', + 'selector': '[expr17]', 'expressions': [ { @@ -606,11 +797,11 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') getComponent ) { return template( - '', + '', [ { - 'redundantAttribute': 'expr19', - 'selector': '[expr19]', + 'redundantAttribute': 'expr20', + 'selector': '[expr20]', 'expressions': [ { @@ -637,8 +828,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') 'slots': [], 'attributes': [], - 'redundantAttribute': 'expr20', - 'selector': '[expr20]' + 'redundantAttribute': 'expr21', + 'selector': '[expr21]' }, { 'type': bindingTypes.TAG, @@ -652,8 +843,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') 'slots': [], 'attributes': [], - 'redundantAttribute': 'expr21', - 'selector': '[expr21]' + 'redundantAttribute': 'expr22', + 'selector': '[expr22]' }, { 'type': bindingTypes.TAG, @@ -667,8 +858,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') 'slots': [], 'attributes': [], - 'redundantAttribute': 'expr22', - 'selector': '[expr22]' + 'redundantAttribute': 'expr23', + 'selector': '[expr23]' }, { 'type': bindingTypes.TAG, @@ -682,8 +873,8 @@ riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error') 'slots': [], 'attributes': [], - 'redundantAttribute': 'expr23', - 'selector': '[expr23]' + 'redundantAttribute': 'expr24', + 'selector': '[expr24]' } ] ); diff --git a/resources/js/components/modal.riot b/resources/js/components/modal.riot new file mode 100644 index 0000000..5c252fc --- /dev/null +++ b/resources/js/components/modal.riot @@ -0,0 +1,84 @@ + + + + + \ No newline at end of file diff --git a/resources/js/components/users.riot b/resources/js/components/users.riot index 55e5dc7..c64cd75 100644 --- a/resources/js/components/users.riot +++ b/resources/js/components/users.riot @@ -51,27 +51,14 @@ - + + + + Delete + +
state.users.length }>
@@ -92,6 +79,12 @@ import axios from 'axios' import remove from 'lodash.remove' + import * as riot from 'riot' + import AppModal from './modal.riot' + + riot.register('app-modal', AppModal) + riot.mount('app-modal') + /** * * @@ -116,18 +109,33 @@ }, handleDelete(event, user) { + event.preventDefault() - axios.delete('/api/users/' + user._id) - .then((response) => { + const customEvent = new CustomEvent('open', { + 'detail': { + 'confirm': () => { + axios.delete('/api/users/' + user._id) + .then((response) => { + + // removing from buckets + remove(this.state.users, function(u) { + return u._id === user._id + }) + + this.update() + }) + }, + + // @TODO find a better solution to create body text + 'body': 'Do you want delete ' + user.email + '?' + } + }); - // removing from buckets - remove(this.state.users, function(u) { - return u._id === user._id - }) + this.$('#user-delete-confirm').dispatchEvent(customEvent); - this.update() - }) + /** + */ }, /** diff --git a/src/http/api/users.ts b/src/http/api/users.ts index 01e177e..96591ed 100644 --- a/src/http/api/users.ts +++ b/src/http/api/users.ts @@ -6,7 +6,6 @@ import { uuid } from '../../rules/uuid.ts' const router = Router() - /** * get all users * diff --git a/src/http/auth.ts b/src/http/auth.ts index 5d575e0..9c427f8 100644 --- a/src/http/auth.ts +++ b/src/http/auth.ts @@ -33,7 +33,6 @@ router.post('/', async function(request, response) result = userRepository.verifyPassword(user, body.password) if (result) { - response.cookie('auth-token', jwt) } }