diff --git a/Memo.md b/Memo.md index adf318c..d8ea7e5 100644 --- a/Memo.md +++ b/Memo.md @@ -149,6 +149,8 @@ yarn add monaco-editor yarn add vee-validate +yarn add es6-promise + yarn run build yarn run build && yarn run hot diff --git a/app/Http/Controllers/Auth/Rest/RestLoginController.php b/app/Http/Controllers/Auth/Rest/RestLoginController.php index 03c6472..5a609da 100644 --- a/app/Http/Controllers/Auth/Rest/RestLoginController.php +++ b/app/Http/Controllers/Auth/Rest/RestLoginController.php @@ -61,4 +61,23 @@ public function user(Request $request) { // 認証ユーザ情報を返す return ['check' => Auth::check(), 'user' => Auth::user()]; } + + /** + * update. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function update(Request $request) { + $user = Auth::user(); + + if ($request->has('email')) $user->email = $request->input('email'); + if ($request->has('name')) $user->name = $request->input('name'); + //if ($request->has('password')) $user->name = $request->input('password'); + if ($request->has('markdown')) $user->markdown = $request->input('markdown'); + if ($request->has('gtoken')) $user->gtoken = $request->input('gtoken'); + $user->save(); + + return ['update' => true, 'user' => Auth::user()]; + } } diff --git a/package.json b/package.json index 2910c84..990f740 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "dependencies": { "bootstrap-honoka": "^4.1.3", + "es6-promise": "^4.2.5", "monaco-editor": "^0.15.6", "open-iconic": "^1.1.1", "tui-editor": "^1.2.6", diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 4c6c2cc..a7b9f74 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,45 +1,54 @@ { "/js/app.js": "/js/app.js", "/css/app.css": "/css/app.css", - "/0.ff766803b30bd3c7713c.hot-update.js": "/0.ff766803b30bd3c7713c.hot-update.js", - "/0.80bde75d7328f16e1c45.hot-update.js": "/0.80bde75d7328f16e1c45.hot-update.js", - "/0.b0bf0b80491845fd4a09.hot-update.js": "/0.b0bf0b80491845fd4a09.hot-update.js", - "/0.51dd5a4fb06074459f97.hot-update.js": "/0.51dd5a4fb06074459f97.hot-update.js", - "/0.01bbefb99099980c9bd5.hot-update.js": "/0.01bbefb99099980c9bd5.hot-update.js", - "/0.4a9dba3d39478ebb77d8.hot-update.js": "/0.4a9dba3d39478ebb77d8.hot-update.js", - "/0.e763779e63a90dc58edf.hot-update.js": "/0.e763779e63a90dc58edf.hot-update.js", - "/0.4bd9b3a7835f6466ec50.hot-update.js": "/0.4bd9b3a7835f6466ec50.hot-update.js", - "/0.4eecc91bb61ea7ee9ff0.hot-update.js": "/0.4eecc91bb61ea7ee9ff0.hot-update.js", - "/0.13657acccc146062c7e6.hot-update.js": "/0.13657acccc146062c7e6.hot-update.js", - "/0.2a3038d36867617f9be4.hot-update.js": "/0.2a3038d36867617f9be4.hot-update.js", - "/0.06d845d61f57eabdfe8d.hot-update.js": "/0.06d845d61f57eabdfe8d.hot-update.js", - "/0.48c35aa99da76221bcaa.hot-update.js": "/0.48c35aa99da76221bcaa.hot-update.js", - "/0.5a81fd74c6b991774d4b.hot-update.js": "/0.5a81fd74c6b991774d4b.hot-update.js", - "/0.869ba0dc8fc466fdd9fc.hot-update.js": "/0.869ba0dc8fc466fdd9fc.hot-update.js", - "/0.450024d9afbc03849e15.hot-update.js": "/0.450024d9afbc03849e15.hot-update.js", - "/0.fa62c66ad5d04c278f31.hot-update.js": "/0.fa62c66ad5d04c278f31.hot-update.js", - "/0.11c87fc139c432424d38.hot-update.js": "/0.11c87fc139c432424d38.hot-update.js", - "/0.af16433dd584f86d396e.hot-update.js": "/0.af16433dd584f86d396e.hot-update.js", - "/0.6a09e68b9b9a24ef702a.hot-update.js": "/0.6a09e68b9b9a24ef702a.hot-update.js", - "/0.b03beebb7b6f991183ab.hot-update.js": "/0.b03beebb7b6f991183ab.hot-update.js", - "/0.5ed6fa3d2a5a5439e36d.hot-update.js": "/0.5ed6fa3d2a5a5439e36d.hot-update.js", - "/0.f2a5fbcd0d7d70b6aa4d.hot-update.js": "/0.f2a5fbcd0d7d70b6aa4d.hot-update.js", - "/0.bdc2c04ec1f37479787c.hot-update.js": "/0.bdc2c04ec1f37479787c.hot-update.js", - "/0.83c96ae32edd2a365b56.hot-update.js": "/0.83c96ae32edd2a365b56.hot-update.js", - "/0.7f665706317c7abd6f83.hot-update.js": "/0.7f665706317c7abd6f83.hot-update.js", - "/0.240c50214addc2102413.hot-update.js": "/0.240c50214addc2102413.hot-update.js", - "/0.2184d6790dbcbd75aa53.hot-update.js": "/0.2184d6790dbcbd75aa53.hot-update.js", - "/0.3854d95516836515b281.hot-update.js": "/0.3854d95516836515b281.hot-update.js", - "/0.0d617251ee53c3e0c263.hot-update.js": "/0.0d617251ee53c3e0c263.hot-update.js", - "/0.a08acef3e62d02c91afb.hot-update.js": "/0.a08acef3e62d02c91afb.hot-update.js", - "/0.e73649aa85d6ad0dacec.hot-update.js": "/0.e73649aa85d6ad0dacec.hot-update.js", - "/0.788c6b329d9f86f14e39.hot-update.js": "/0.788c6b329d9f86f14e39.hot-update.js", - "/0.89f4104f65a925c1ffcf.hot-update.js": "/0.89f4104f65a925c1ffcf.hot-update.js", - "/0.7ffc1623fb752be3737e.hot-update.js": "/0.7ffc1623fb752be3737e.hot-update.js", - "/0.418ccb512eaaed127ff1.hot-update.js": "/0.418ccb512eaaed127ff1.hot-update.js", - "/0.5cd6a7fad6d2bf08e375.hot-update.js": "/0.5cd6a7fad6d2bf08e375.hot-update.js", - "/0.fd74102df7d2bb83580c.hot-update.js": "/0.fd74102df7d2bb83580c.hot-update.js", - "/0.e0f5d0e6b9fae6dec103.hot-update.js": "/0.e0f5d0e6b9fae6dec103.hot-update.js", - "/0.938c658e37a3a2a357c1.hot-update.js": "/0.938c658e37a3a2a357c1.hot-update.js", - "/0.ddd46225ecc68cab3a08.hot-update.js": "/0.ddd46225ecc68cab3a08.hot-update.js" + "/0.3fa18f54dc652bd5bd62.hot-update.js": "/0.3fa18f54dc652bd5bd62.hot-update.js", + "/0.4758d0eb373ed9c7a77f.hot-update.js": "/0.4758d0eb373ed9c7a77f.hot-update.js", + "/0.408c1efae6deaa4820d4.hot-update.js": "/0.408c1efae6deaa4820d4.hot-update.js", + "/0.6afdab49e83178d33fd7.hot-update.js": "/0.6afdab49e83178d33fd7.hot-update.js", + "/0.3abbc233bb12b604e237.hot-update.js": "/0.3abbc233bb12b604e237.hot-update.js", + "/0.46a2e3d86208fd970aba.hot-update.js": "/0.46a2e3d86208fd970aba.hot-update.js", + "/0.7eb30545e33373e6b376.hot-update.js": "/0.7eb30545e33373e6b376.hot-update.js", + "/0.9c96042e7021c979b1b7.hot-update.js": "/0.9c96042e7021c979b1b7.hot-update.js", + "/0.5cda46f2a9706266ca26.hot-update.js": "/0.5cda46f2a9706266ca26.hot-update.js", + "/0.28f355477668549ce242.hot-update.js": "/0.28f355477668549ce242.hot-update.js", + "/0.3e48d2e1567939c010b7.hot-update.js": "/0.3e48d2e1567939c010b7.hot-update.js", + "/0.ded744609dcbb4dbad01.hot-update.js": "/0.ded744609dcbb4dbad01.hot-update.js", + "/0.545710289cfebeadad50.hot-update.js": "/0.545710289cfebeadad50.hot-update.js", + "/0.d6699d1edef9a4be2dd4.hot-update.js": "/0.d6699d1edef9a4be2dd4.hot-update.js", + "/0.4fb3fd4b6c06c960e316.hot-update.js": "/0.4fb3fd4b6c06c960e316.hot-update.js", + "/0.1e2f9f8ee7383daf4afc.hot-update.js": "/0.1e2f9f8ee7383daf4afc.hot-update.js", + "/0.214c77e1d66667111318.hot-update.js": "/0.214c77e1d66667111318.hot-update.js", + "/0.e40b719474da96d5c5b7.hot-update.js": "/0.e40b719474da96d5c5b7.hot-update.js", + "/0.57e1e5c783d15dd50c8f.hot-update.js": "/0.57e1e5c783d15dd50c8f.hot-update.js", + "/0.6ad50b6f672b2d5b5632.hot-update.js": "/0.6ad50b6f672b2d5b5632.hot-update.js", + "/0.c19474f3402d74929308.hot-update.js": "/0.c19474f3402d74929308.hot-update.js", + "/0.59f67fb8c02b68b9b3a4.hot-update.js": "/0.59f67fb8c02b68b9b3a4.hot-update.js", + "/0.69c0b42840b671754378.hot-update.js": "/0.69c0b42840b671754378.hot-update.js", + "/0.61bf3ff8830a466448f6.hot-update.js": "/0.61bf3ff8830a466448f6.hot-update.js", + "/0.c2998b4f392ce2691190.hot-update.js": "/0.c2998b4f392ce2691190.hot-update.js", + "/0.7dd462e0793eee905268.hot-update.js": "/0.7dd462e0793eee905268.hot-update.js", + "/0.c2e45820c89d5275ad14.hot-update.js": "/0.c2e45820c89d5275ad14.hot-update.js", + "/0.4bfc791007a71d5526a6.hot-update.js": "/0.4bfc791007a71d5526a6.hot-update.js", + "/0.e8000df6680050f1eca9.hot-update.js": "/0.e8000df6680050f1eca9.hot-update.js", + "/0.550925f23ffb2c59c72a.hot-update.js": "/0.550925f23ffb2c59c72a.hot-update.js", + "/0.a84656a652c775d9ca0a.hot-update.js": "/0.a84656a652c775d9ca0a.hot-update.js", + "/0.df65e0da83e1d8a4ff8e.hot-update.js": "/0.df65e0da83e1d8a4ff8e.hot-update.js", + "/0.5543dc8000869254150f.hot-update.js": "/0.5543dc8000869254150f.hot-update.js", + "/0.b5aaa51d3a09ccd68322.hot-update.js": "/0.b5aaa51d3a09ccd68322.hot-update.js", + "/0.c51c713e1b569b5263b8.hot-update.js": "/0.c51c713e1b569b5263b8.hot-update.js", + "/0.c3b9ce9c6d270eeb841a.hot-update.js": "/0.c3b9ce9c6d270eeb841a.hot-update.js", + "/0.83800e0d19959a6c70a8.hot-update.js": "/0.83800e0d19959a6c70a8.hot-update.js", + "/0.badbb3a51fd191717312.hot-update.js": "/0.badbb3a51fd191717312.hot-update.js", + "/0.fa37b9ff00c77f9f677f.hot-update.js": "/0.fa37b9ff00c77f9f677f.hot-update.js", + "/0.4376c4c6ec8fc7f0af05.hot-update.js": "/0.4376c4c6ec8fc7f0af05.hot-update.js", + "/0.e4cb93fd1dd623801b5a.hot-update.js": "/0.e4cb93fd1dd623801b5a.hot-update.js", + "/0.7050559ef2185f361757.hot-update.js": "/0.7050559ef2185f361757.hot-update.js", + "/0.c68925b401b99db180b6.hot-update.js": "/0.c68925b401b99db180b6.hot-update.js", + "/0.51c9ae20031a3c316313.hot-update.js": "/0.51c9ae20031a3c316313.hot-update.js", + "/0.2f1f5dbebd65d91f5bca.hot-update.js": "/0.2f1f5dbebd65d91f5bca.hot-update.js", + "/0.04652462f22840ede6d0.hot-update.js": "/0.04652462f22840ede6d0.hot-update.js", + "/0.09effc604df047e4128f.hot-update.js": "/0.09effc604df047e4128f.hot-update.js", + "/0.583705f3555e206b583b.hot-update.js": "/0.583705f3555e206b583b.hot-update.js", + "/0.dfd1daa34991821a7d52.hot-update.js": "/0.dfd1daa34991821a7d52.hot-update.js", + "/0.663597de208af1b692b6.hot-update.js": "/0.663597de208af1b692b6.hot-update.js" } diff --git a/resources/js/app.js b/resources/js/app.js index ed1c61b..fde5757 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -10,6 +10,9 @@ require('./bootstrap'); require('./halocontext/jquery.halocontext'); require('./sidebar/bootstrap-sidebar'); +// import es6 promise +import 'es6-promise/auto'; + // import VeeValidate import VeeValidate, { Validator } from'vee-validate'; @@ -19,6 +22,10 @@ import Editor from 'tui-editor/dist/tui-editor-Editor-all.js'; // require Vue window.Vue = require('vue'); +// import Vuex +import Vuex from 'vuex'; +window.Vue.use(Vuex); + // use VeeValidate window.Vue.use(VeeValidate); @@ -48,12 +55,23 @@ Vue.component('example-component', require('./components/ExampleComponent.vue')) // return Vue.component(_.last(key.split('/')).split('.')[0], files(key)) // }) +// const editor = new Editor({ +// el: document.querySelector('#edit-section'), +// //viewer: true, +// initialEditType: 'markdown', +// useCommandShortcut: true, +// previewStyle: 'vertical', +// height: '100%', +// initialValue: '', +// language: 'ja', +// exts: ['scrollSync', 'colorSyntax', 'uml', 'chart', 'mark', 'table'] +// }); + /** * Next, we will create a fresh Vue application instance and attach it to * the page. Then, you may begin adding components to this application * or customize the JavaScript scaffolding to fit your unique needs. */ - const app = new Vue({ el: '#app', methods: { @@ -70,18 +88,6 @@ const app = new Vue({ } }, mounted() { - var editor = new Editor({ - el: document.querySelector('#editSection'), - //viewer: true, - initialEditType: 'markdown', - useCommandShortcut: true, - previewStyle: 'vertical', - height: '100%', - initialValue: '', - language: 'ja', - exts: ['scrollSync', 'colorSyntax', 'uml', 'chart', 'mark', 'table'] - }); - // const params = { path : 'welcome.md' }; // const url = "http://"+this.backend+"/gdrive"; @@ -101,8 +107,63 @@ const app = new Vue({ } }); +const store = new Vuex.Store({ + state: { + user: null, + editor: new Editor({ + el: document.querySelector('#edit-section'), + //viewer: true, + initialEditType: 'markdown', + useCommandShortcut: true, + previewStyle: 'vertical', + height: '100%', + initialValue: '', + language: 'ja', + exts: ['scrollSync', 'colorSyntax', 'uml', 'chart', 'mark', 'table'], + events: {change: function() { + //console.log("change markdown."); + if (store.state.user) + store.state.user.markdown = store.state.editor.getMarkdown(); + //console.log("update markdown."); + }} + }) + }, + // Storeに対するGetterを定義 + getters: { + user(state) { + return state.user; + }, + editor(state) { + return state.editor; + }, + editorMarkdown(state) { + return state.editor.getMarkdown(); + } + }, + // Storeに対するActionを定義 + actions: { + setUser (context, user) { + context.commit('SET_USER', user); // Actionはmutationsを呼ぶ + }, + setMarkdown (context, markdown) { + context.commit('SET_MARKDOWN', markdown); // Actionはmutationsを呼ぶ + }, + }, + mutations: { + SET_USER (state, user) { + state.user = user; + state.editor.setMarkdown(state.user.markdown, false/*cursorToEndopt*/); + //console.log(state.user); + }, + SET_MARKDOWN (state, markdown) { + state.editor.setMarkdown(markdown, false/*cursorToEndopt*/); + }, + }, +}); + const login = new Vue({ el: '#login', + store: store, data: { name: null, email: null, @@ -129,14 +190,17 @@ const login = new Vue({ // バリデーションする this.$validator.errors.remove('notification'); + this.$validator.errors.remove('unmatch'); + this.$validator.errors.remove('unregist'); + this.$validator.validateAll().then((result) => { if ( this.regist && !result ) { // 新規登録で入力エラー - this.$validator.errors.add({field: 'notification', msg: '入力エラーがあります...'}); + this.$validator.errors.add({field: 'notification', msg: 'msg'}); return false; - } else if ( this.regist && (errors.has('email') || errors.has('password')) ) { + } else if ( !this.regist && (this.$validator.errors.has('email') || this.$validator.errors.has('password')) ) { // ログインで入力エラー - this.$validator.errors.add({field: 'notification', msg: '入力エラーがあります...'}); + this.$validator.errors.add({field: 'notification', msg: 'msg'}); return false; } }); @@ -145,20 +209,39 @@ const login = new Vue({ // ユーザ登録する axios.post('/api/register', { name: this.name, email: this.email, password: this.password, password_confirmation: this.password_confirmation }) .then(function(response) { - alert(JSON.stringify(response.data)); - }) + // alert(JSON.stringify(response.data)); + if(response.data.register) { + $('#login-modal').modal('hide'); + this.$store.dispatch('setUser', response.data.user); + } else { + this.$validator.errors.add({field: 'unregist', msg: 'msg'}); + } + }.bind(this))// thisを使う .catch(function(error) { - console.log('ERROR!! occurred in Backend.') - }); + console.log('ERROR!! occurred in Backend.'); + // errorを展開する alert(error.response.data.errors.email[0]); + Object.keys(error.response.data.errors).forEach(function(errorObjKey){ + error.response.data.errors[errorObjKey].forEach(function(errorObj, index, ar){ + this.$validator.errors.add({field: 'regist_error', msg: errorObj}); + }, this); + }, this); + }.bind(this));// thisを使う } else { // ユーザ認証する axios.post('/api/login', { email: this.email, password: this.password }) .then(function(response) { - alert(JSON.stringify(response.data)); - }) + // alert(JSON.stringify(response.data)); + if(response.data.auth) { + $('#login-modal').modal('hide'); + this.$store.dispatch('setUser', response.data.user); + this.$store.dispatch('setMarkdown', response.data.user.markdown); + } else { + this.$validator.errors.add({field: 'unmatch', msg: 'msg'}); + } + }.bind(this))// thisを使う .catch(function(error) { - console.log('ERROR!! occurred in Backend.') - }); + console.log('ERROR!! occurred in Backend.'); + }.bind(this));// thisを使う } } } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 7ceef66..81eca89 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -436,7 +436,7 @@ @yield('content') -
+