Skip to content

Commit

Permalink
Merge pull request #5 from openjournalteam/feat/updatePanel
Browse files Browse the repository at this point in the history
Feat/update panel
  • Loading branch information
rahmanramsi authored Sep 19, 2022
2 parents 973eb57 + b507e5e commit 14b7dc6
Show file tree
Hide file tree
Showing 10 changed files with 1,671 additions and 2,683 deletions.
30 changes: 6 additions & 24 deletions OjtPageHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,14 @@ public function updatePanel($args, $request)
{
$plugin = $this->ojtPlugin;

$ojtPlugin = json_decode($_POST['ojtPlugin']);
// dd($ojtPlugin);
// $payload = [
// 'token' => $ojtPlugin->token,
// 'journal_url' => $this->baseUrl,
// ];

// $response = $this->curl($payload, API . 'get_download_link', true);
// if ($response == false) {
// $json['error'] = 1;
// $json['msg'] = "There's a problem on the server, please try again later.";
// return showJson($json);
// }

// if ($response->error == 1) {
// $json['error'] = 1;
// $json['msg'] = $response->msg;
// return showJson($json);
// }

// $data = $response->data;


$ojtPlugin = json_decode($request->getUserVar('ojtPlugin'));

$url = $ojtPlugin->link_download;
// trying to install plugin
try {
$plugin->updatePanel($url);
// $plugin->updatePanel($data->download_link);
} catch (Exception $e) {
$json['error'] = 1;
$json['msg'] = $e->getMessage();
Expand Down Expand Up @@ -96,7 +78,7 @@ public function index($args, $request)
$ojtPlugin->pageName = 'ojt';

$ojtPlugin->javascript = [
$request->getBaseUrl() . '/lib/pkp/lib/vendor/components/jquery/jquery' . $min . '.js',
$request->getBaseUrl() . '/lib/pkp/lib/vendor/components/jquery/jquery.min.js',
$pluginFullUrl . '/assets/vendors/sweetalert/sweetalert2.all.min.js',
$pluginFullUrl . '/assets/js/theme.js',
$pluginFullUrl . '/assets/js/jquery.form.min.js',
Expand Down Expand Up @@ -196,7 +178,7 @@ public function installPlugin($args, $request)
$pluginToInstall = json_decode($_POST['plugin']);
$license = $_POST['license'] ?? false;

if (isset($_POST['upgrade']) && $targetPlugin = @include($plugin->getModulesPath() . "/$pluginToInstall->folder/index.php")) {
if (isset($_POST['update']) && $targetPlugin = @include($plugin->getModulesPath() . "/$pluginToInstall->folder/index.php")) {
$license = $targetPlugin->getSetting($this->contextId, 'license');
}

Expand Down
27 changes: 13 additions & 14 deletions assets/js/mainAlpine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ function checkUpdate() {
updateAvailable: false,
data: {},
checkUpdate: async function () {
let res = await fetch(
"https://demo.ini-sudah.online/index.php/wp-json/openjournalvalidation/v1/ojtpanel/check_update",
{
mode: "cors",
}
);
// let res = await fetch("http://localhost/update.json", {
// mode: "cors",
// });
let ojtPlugin = await res.json();
try {
let res = await fetch(
"https://openjournaltheme.com/index.php/wp-json/openjournalvalidation/v1/ojtplugin/check_update",
{
mode: "cors",
}
);
let ojtPlugin = await res.json();

this.data = ojtPlugin;
this.data = ojtPlugin;

if (ojtPlugin.latest_version > ojtPluginVersion) {
this.updateAvailable = true;
}
if (ojtPlugin.latest_version > ojtPluginVersion) {
this.updateAvailable = true;
}
} catch (error) {}
},
doUpdate() {
Swal.fire({
Expand Down
Loading

0 comments on commit 14b7dc6

Please sign in to comment.