Skip to content

Commit

Permalink
Updates page fixes..
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Nov 20, 2019
1 parent d0dadd3 commit bba0e50
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 119 deletions.
21 changes: 12 additions & 9 deletions app/Http/Controllers/Install/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,43 +104,46 @@ public function update($alias, $version)
*/
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('install/updates/download')
];

// Unzip
$json['step'][] = [
$steps[] = [
'text' => trans('modules.installation.unzip', ['module' => $name]),
'url' => url('install/updates/unzip')
];

// File Copy
$json['step'][] = [
$steps[] = [
'text' => trans('modules.installation.file_copy', ['module' => $name]),
'url' => url('install/updates/file-copy')
];

// Finish installation
$json['step'][] = [
$steps[] = [
'text' => trans('modules.installation.finish', ['module' => $name]),
'url' => url('install/updates/finish')
];

// Redirect
$json['step'][] = [
$steps[] = [
'text' => trans('modules.installation.redirect', ['module' => $name]),
'url' => url('install/updates/redirect')
];

return response()->json($json);
return response()->json([
'success' => true,
'error' => false,
'data' => $steps,
'message' => null
]);
}

/**
Expand Down
45 changes: 30 additions & 15 deletions app/Utilities/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public static function download($alias, $version, $installed)
if ($response instanceof RequestException) {
return [
'success' => false,
'errors' => trans('modules.errors.download', ['module' => $name]),
'error' => true,
'message' => trans('modules.errors.download', ['module' => $alias]),
'data' => [
'path' => $path
]
Expand All @@ -69,7 +70,8 @@ public static function download($alias, $version, $installed)
if (!$uploaded) {
return [
'success' => false,
'errors' => trans('modules.errors.zip', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.zip', ['module' => $alias]),
'data' => [
'path' => $path
]
Expand All @@ -81,23 +83,26 @@ public static function download($alias, $version, $installed)

return [
'success' => true,
'errors' => false,
'error' => false,
'message' => null,
'data' => [
'path' => $path
]
];
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.download', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.download', ['module' => $alias]),
'data' => []
];
}
}

return [
'success' => false,
'errors' => trans('modules.errors.download', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.download', ['module' => $alias]),
'data' => [
'path' => $path
]
Expand All @@ -116,7 +121,8 @@ public static function unzip($path, $alias, $version, $installed)
if (($zip->open($file) !== true) || !$zip->extractTo($temp_path)) {
return [
'success' => false,
'errors' => trans('modules.errors.unzip', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.unzip', ['module' => $alias]),
'data' => [
'path' => $path
]
Expand All @@ -133,15 +139,17 @@ public static function unzip($path, $alias, $version, $installed)

return [
'success' => true,
'errors' => false,
'error' => false,
'message' => null,
'data' => [
'path' => $path
]
];
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.unzip', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.unzip', ['module' => $alias]),
'data' => []
];
}
Expand All @@ -156,7 +164,8 @@ public static function fileCopy($path, $alias, $version, $installed)
if (!File::copyDirectory($temp_path, base_path())) {
return [
'success' => false,
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => [
'path' => $path
]
Expand All @@ -177,7 +186,8 @@ public static function fileCopy($path, $alias, $version, $installed)
if (!File::copyDirectory($temp_path, $module_path)) {
return [
'success' => false,
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => [
'path' => $path
]
Expand Down Expand Up @@ -208,15 +218,17 @@ public static function fileCopy($path, $alias, $version, $installed)

return [
'success' => true,
'errors' => false,
'error' => false,
'message' => null,
'data' => [
'path' => $path
]
];
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => []
];
}
Expand All @@ -228,7 +240,8 @@ public static function finish($alias, $version, $installed)
if (($alias == 'core') && (version('short') != $version)) {
return [
'success' => false,
'errors' => trans('modules.errors.file_copy', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.file_copy', ['module' => $alias]),
'data' => []
];
}
Expand All @@ -241,13 +254,15 @@ public static function finish($alias, $version, $installed)

return [
'success' => true,
'errors' => false,
'error' => false,
'message' => null,
'data' => []
];
} catch (\Exception $e) {
return [
'success' => false,
'errors' => trans('modules.errors.finish', ['module' => $alias]),
'error' => true,
'message' => trans('modules.errors.finish', ['module' => $alias]),
'data' => []
];
}
Expand Down
2 changes: 1 addition & 1 deletion app/Utilities/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function changelog()
continue;
}

$output .= '<h2><span class="label label-success">'.$release->tag_name.'</span></h2>';
$output .= '<h2><span class="badge badge-pill badge-success">' . $release->tag_name . '</span></h2>';

$output .= $parsedown->text($release->body);

Expand Down
145 changes: 145 additions & 0 deletions resources/assets/js/views/install/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/

require('../../bootstrap');

import Vue from 'vue';

import Global from './../../mixins/global';

import {Progress} from 'element-ui';

Vue.use(Progress);

const app = new Vue({
el: '#app',

mixins: [
Global
],

components: {
[Progress.name]: Progress,
},

data: function () {
return {
changelog: {
show:false,
html: null
},
update: {
steps: [],
steps_total: 0,
total: 0,
path: '',
status: 'success',
html: ''
},
page: 'check',
name: null,
version: null
}
},

mounted() {
if (document.getElementById('page') != null && document.getElementById('page').value == 'update') {
this.steps();
}
},

methods: {
onChangelog() {
axios.get(url + '/install/updates/changelog')
.then(response => {
this.changelog.show = true;
this.changelog.html = response.data;
})
.catch(e => {
this.errors.push(e)
})
.finally(function () {
// always executed
});
},

steps() {
let name = document.getElementById('name').value;

axios.post(url + '/install/updates/steps', {
name: name,
version: version
})
.then(response => {
if (response.data.error) {
this.update.status = 'exception';
this.update.html = '<div class="text-danger">' + response.data.message + '</div>';
}

// Set steps
if (response.data.data) {
this.update.steps = response.data.data;
this.update.steps_total = this.update.steps.length;

this.next();
}
})
.catch(error => {
});
},

next() {
let data = this.update.steps.shift();

let name = document.getElementById('name').value;
let alias = document.getElementById('alias').value;
let version = document.getElementById('version').value;
let installed = document.getElementById('installed').value;

if (data) {
this.update.total = (100 - ((this.update.steps.length / this.update.steps_total) * 100));

this.update.html = '<span class="text-default"><i class="fa fa-spinner fa-spin update-spin"></i> ' + data['text'] + '</span> </br>';

axios.post(data.url, {
name: name,
alias: alias,
version: version,
installed: installed,
path: this.update.path,
})
.then(response => {
if (response.data.error) {
this.update.status = 'exception';
this.update.html = '<div class="text-danger"><i class="fa fa-times update-error"></i> ' + response.data.message + '</div>';
}

if (response.data.success) {
this.update.status = 'success';
}

if (response.data.data.path) {
this.update.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 => {
});
}
}
}
});

0 comments on commit bba0e50

Please sign in to comment.