From 771d73f0d1529faa98b53ebd3d68f6f7114a95a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 20 Nov 2019 17:11:35 +0300 Subject: [PATCH] App store install purchase app --- app/Http/Controllers/Modules/Item.php | 17 ++-- app/Traits/Modules.php | 26 ++++-- resources/assets/js/views/install/update.js | 2 +- resources/assets/js/views/modules/item.js | 91 ++++++++++++++++++- resources/views/modules/home/index.blade.php | 4 + resources/views/modules/item/show.blade.php | 23 ++++- .../views/partials/modules/bar.blade.php | 1 + 7 files changed, 143 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Modules/Item.php b/app/Http/Controllers/Modules/Item.php index 5af177239..a06d5d640 100644 --- a/app/Http/Controllers/Modules/Item.php +++ b/app/Http/Controllers/Modules/Item.php @@ -78,31 +78,34 @@ class Item extends Controller */ public function steps(Request $request) { - $json = []; - $json['step'] = []; + $steps = []; $name = $request['name']; - $version = $request['version']; // Download - $json['step'][] = [ + $steps[] = [ 'text' => trans('modules.installation.download', ['module' => $name]), 'url' => url('apps/download') ]; // Unzip - $json['step'][] = [ + $steps[] = [ 'text' => trans('modules.installation.unzip', ['module' => $name]), 'url' => url('apps/unzip') ]; // Download - $json['step'][] = [ + $steps[] = [ 'text' => trans('modules.installation.install', ['module' => $name]), 'url' => url('apps/install') ]; - return response()->json($json); + return response()->json([ + 'success' => true, + 'error' => false, + 'data' => $steps, + 'message' => null + ]); } /** diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php index 87ff99ff1..daf010204 100644 --- a/app/Traits/Modules.php +++ b/app/Traits/Modules.php @@ -335,14 +335,16 @@ trait Modules return [ 'success' => true, - 'errors' => false, + 'error' => false, + 'message' => null, 'data' => $data, ]; } return [ 'success' => false, - 'errors' => true, + 'error' => true, + 'message' => null, 'data' => null, ]; } @@ -359,7 +361,8 @@ trait Modules if (!$zip->open($file) || !$zip->extractTo($temp_path)) { return [ 'success' => false, - 'errors' => true, + 'error' => true, + 'message' => null, 'data' => null, ]; } @@ -375,7 +378,8 @@ trait Modules return [ 'success' => true, - 'errors' => false, + 'error' => false, + 'message' => null, 'data' => $data, ]; } @@ -414,8 +418,9 @@ trait Modules return [ 'success' => true, - 'installed' => url("apps/post/" . $module->alias), - 'errors' => false, + 'redirect' => url("apps/post/" . $module->alias), + 'error' => false, + 'message' => null, 'data' => $data, ]; } @@ -439,7 +444,8 @@ trait Modules return [ 'success' => true, - 'errors' => false, + 'error' => false, + 'message' => null, 'data' => $data ]; } @@ -460,7 +466,8 @@ trait Modules return [ 'success' => true, - 'errors' => false, + 'error' => false, + 'message' => null, 'data' => $data ]; } @@ -481,7 +488,8 @@ trait Modules return [ 'success' => true, - 'errors' => false, + 'error' => false, + 'message' => null, 'data' => $data ]; } diff --git a/resources/assets/js/views/install/update.js b/resources/assets/js/views/install/update.js index 8e1309945..cef22a70f 100644 --- a/resources/assets/js/views/install/update.js +++ b/resources/assets/js/views/install/update.js @@ -100,7 +100,7 @@ const app = new Vue({ let installed = document.getElementById('installed').value; if (data) { - this.update.total = (100 - ((this.update.steps.length / this.update.steps_total) * 100)); + this.update.total = (100 - ((this.update.steps.length / this.update.steps_total) * 100)).toFixed(0); this.update.html = ' ' + data['text'] + '
'; diff --git a/resources/assets/js/views/modules/item.js b/resources/assets/js/views/modules/item.js index 20e4a1662..844f3b0ac 100644 --- a/resources/assets/js/views/modules/item.js +++ b/resources/assets/js/views/modules/item.js @@ -10,6 +10,10 @@ import Vue from 'vue'; import Global from '../../mixins/global'; +import {Progress} from 'element-ui'; + +Vue.use(Progress); + const app = new Vue({ el: '#app', @@ -17,6 +21,10 @@ const app = new Vue({ Global ], + components: { + [Progress.name]: Progress, + }, + mounted() { this.onGetReviews('', 1); }, @@ -24,7 +32,17 @@ const app = new Vue({ data: function () { return { reviews: '', - faq: false + faq: false, + installation: { + show: false, + steps: [], + steps_total: 0, + total: 0, + path: '', + version: '', + status: 'success', + html: '' + }, } }, @@ -43,6 +61,77 @@ const app = new Vue({ onShowFaq() { this.faq = true; + }, + + onInstall(path, name, version) { + this.installation.show = true; + this.installation.total = 0; + this.installation.path = path; + this.installation.version = version; + + axios.post(url + '/apps/steps', { + name: name, + version: version + }) + .then(response => { + if (response.data.error) { + this.installation.status = 'exception'; + this.installation.html = '
' + response.data.message + '
'; + } + + // Set steps + if (response.data.data) { + this.installation.steps = response.data.data; + this.installation.steps_total = this.installation.steps.length; + + this.next(); + } + }) + .catch(error => { + }); + }, + + next() { + let data = this.installation.steps.shift(); + + if (data) { + this.installation.total = (100 - ((this.installation.steps.length / this.installation.steps_total) * 100)).toFixed(0); + + this.installation.html = ' ' + data['text'] + '
'; + + axios.post(data.url, { + version: this.installation.version, + path: this.installation.path, + }) + .then(response => { + if (response.data.error) { + this.installation.status = 'exception'; + this.installation.html = '
' + response.data.message + '
'; + } + + if (response.data.success) { + this.installation.status = 'success'; + } + + if (response.data.data.path) { + this.installation.path = response.data.data.path; + } + + if (!response.data.error && !response.data.redirect) { + let self = this; + + setTimeout(function() { + self.next(); + }, 800); + } + + if (response.data.redirect) { + window.location = response.data.redirect; + } + }) + .catch(error => { + }); + } } } }); diff --git a/resources/views/modules/home/index.blade.php b/resources/views/modules/home/index.blade.php index 9fd7d6ea1..6ac915768 100644 --- a/resources/views/modules/home/index.blade.php +++ b/resources/views/modules/home/index.blade.php @@ -61,3 +61,7 @@ @endif @endsection + +@push('scripts_start') + +@endpush diff --git a/resources/views/modules/item/show.blade.php b/resources/views/modules/item/show.blade.php index f365c3ee0..2764372d0 100644 --- a/resources/views/modules/item/show.blade.php +++ b/resources/views/modules/item/show.blade.php @@ -210,16 +210,16 @@ @else @permission('create-modules-item') @if ($module->install) - + @else {{ trans('modules.buy_now') }} @endif @endpermission - @endif + @endif @if ($module->purchase_faq)
@@ -293,6 +293,23 @@ @endif + + @if ($module->install) + + + + + @endif @endsection @push('scripts_start') diff --git a/resources/views/partials/modules/bar.blade.php b/resources/views/partials/modules/bar.blade.php index 2da6fd3b1..3a517bfc3 100644 --- a/resources/views/partials/modules/bar.blade.php +++ b/resources/views/partials/modules/bar.blade.php @@ -5,6 +5,7 @@
{!! Form::select('category', $categories, request('category'), ['class' => 'form-control form-control-sm table-header-search mt-0']) !!} + {{ trans('modules.top_paid') }} {{ trans('modules.new') }} {{ trans('modules.top_free') }}