Fixed the dashboard to allow offline work
This commit is contained in:
@ -305,15 +305,15 @@ class ComponentbuilderModelAjax extends ListModel
|
||||
}
|
||||
catch (DomainException $e)
|
||||
{
|
||||
return $this->getTokenFromVDM($e->getMessage());
|
||||
return $this->getTokenForWiki($e->getMessage());
|
||||
}
|
||||
catch (InvalidArgumentException $e)
|
||||
{
|
||||
return $this->getTokenFromVDM($e->getMessage());
|
||||
return $this->getTokenForWiki($e->getMessage());
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $this->getTokenFromVDM($e->getMessage());
|
||||
return $this->getTokenForWiki($e->getMessage());
|
||||
}
|
||||
|
||||
// get the html
|
||||
@ -322,10 +322,10 @@ class ComponentbuilderModelAjax extends ListModel
|
||||
return ['page' => $page];
|
||||
}
|
||||
|
||||
return $this->getTokenFromVDM();
|
||||
return $this->getTokenForWiki();
|
||||
}
|
||||
|
||||
protected function getTokenFromVDM($message = null)
|
||||
protected function getTokenForWiki($message = null)
|
||||
{
|
||||
if ($message)
|
||||
{
|
||||
@ -333,7 +333,94 @@ class ComponentbuilderModelAjax extends ListModel
|
||||
}
|
||||
|
||||
return ['error' => JText::_('COM_COMPONENTBUILDER_THE_WIKI_CAN_ONLY_BE_LOADED_WHEN_YOUR_JCB_SYSTEM_HAS_INTERNET_CONNECTION')];
|
||||
}
|
||||
}
|
||||
|
||||
public function getVersion($version = null)
|
||||
{
|
||||
// get the token if set
|
||||
$token = JComponentHelper::getParams('com_componentbuilder')->get('gitea_token', false);
|
||||
// only add if token is set
|
||||
if ($token)
|
||||
{
|
||||
// setup a registry
|
||||
$options = new Registry;
|
||||
$options->set('access.token', $token);
|
||||
// get the gitea http
|
||||
try
|
||||
{
|
||||
// get gitea object
|
||||
$gitea = new Gitea($options);
|
||||
// get a list of all the repos tags
|
||||
$tags = $gitea->repo->getListTags('joomla', 'Component-Builder');
|
||||
}
|
||||
catch (DomainException $e)
|
||||
{
|
||||
return $this->getTokenForVersion($e->getMessage());
|
||||
}
|
||||
catch (InvalidArgumentException $e)
|
||||
{
|
||||
return $this->getTokenForVersion($e->getMessage());
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $this->getTokenForVersion($e->getMessage());
|
||||
}
|
||||
// do we have tags returned
|
||||
if (isset($tags[0]) && isset($tags[0]->name))
|
||||
{
|
||||
// get the version
|
||||
$manifest = ComponentbuilderHelper::manifest();
|
||||
$local_version = (string) $manifest->version;
|
||||
$current_version = trim($tags[0]->name, 'vV');
|
||||
|
||||
// now check if this version is out dated
|
||||
if ($current_version === $local_version)
|
||||
{
|
||||
return ['notice' => '<small><span style="color:green;"><span class="icon-shield"></span>' . JText::_('COM_COMPONENTBUILDER_UP_TO_DATE') . '</span></small>'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// check if this is beta version
|
||||
$current_array = array_map(function ($v) { return (int) $v; }, (array) explode('.', $current_version));
|
||||
$local_array = array_map(function ($v) { return (int) $v; }, (array) explode('.', $local_version));
|
||||
if (($local_array[0] > $current_array[0]) ||
|
||||
($local_array[0] == $current_array[0] && $local_array[1] > $current_array[1]) ||
|
||||
($local_array[0] == $current_array[0] && $local_array[1] == $current_array[1] && $local_array[2] > $current_array[2]))
|
||||
{
|
||||
return ['notice' => '<small><span style="color:#F7B033;"><span class="icon-wrench"></span>' . JText::_('COM_COMPONENTBUILDER_BETA_RELEASE') . '</span></small>'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// download link of the latest version
|
||||
$download = "https://git.vdm.dev/api/v1/repos/joomla/Component-Builder/archive/" . $tags[0]->name . ".zip?access_token=" . $token;
|
||||
|
||||
return ['notice' => '<small><span style="color:red;"><span class="icon-warning-circle"></span>' . JText::_('COM_COMPONENTBUILDER_OUT_OF_DATE') . '!</span> <a style="color:green;" href="' .
|
||||
$download . '" title="' . JText::_('COM_COMPONENTBUILDER_YOU_CAN_DIRECTLY_DOWNLOAD_THE_LATEST_UPDATE_OR_USE_THE_JOOMLA_UPDATE_AREA') . '">' . JText::_('COM_COMPONENTBUILDER_DOWNLOAD_UPDATE') . '!</a></small>'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getTokenForVersion();
|
||||
}
|
||||
|
||||
protected function getTokenForVersion($message = null)
|
||||
{
|
||||
// the URL
|
||||
$url = 'https://git.vdm.dev/user/settings/applications';
|
||||
// create link
|
||||
$a = '<small><a style="color:#F7B033;" href="' . $url . '" title="';
|
||||
$a_ = '">';
|
||||
$_a = '</a></small>';
|
||||
|
||||
if ($message)
|
||||
{
|
||||
return ['error' => $a . $message . $a_ . JText::_('COM_COMPONENTBUILDER_GET_TOKEN') . $_a];
|
||||
}
|
||||
|
||||
return ['error' => $a . JText::_('COM_COMPONENTBUILDER_GET_TOKEN_FROM_VDM_TO_GET_UPDATE_NOTICE_AND_ADD_IT_TO_YOUR_GLOBAL_OPTIONS') . $a_ . JText::_('COM_COMPONENTBUILDER_GET_TOKEN') . $_a];
|
||||
}
|
||||
|
||||
|
||||
// Used in joomla_module
|
||||
public function getModuleCode($data)
|
||||
|
@ -416,90 +416,26 @@ class ComponentbuilderModelComponentbuilder extends ListModel
|
||||
$call_url = JUri::base() . 'index.php?option=com_componentbuilder&task=ajax.getWiki&format=json&raw=true&' . JSession::getFormToken() . '=1&name=Home';
|
||||
$document = JFactory::getDocument();
|
||||
$document->addScriptDeclaration('
|
||||
fetch("' . $call_url . '").then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
}).then((result) => {
|
||||
if (typeof result.page !== "undefined") {
|
||||
document.getElementById("wiki-md").innerHTML = result.page;
|
||||
} else if (typeof result.error !== "undefined") {
|
||||
document.getElementById("wiki-md-error").innerHTML = result.error
|
||||
}
|
||||
});');
|
||||
function getWikiPage(){
|
||||
|
||||
fetch("' . $call_url . '").then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
}).then((result) => {
|
||||
if (typeof result.page !== "undefined") {
|
||||
document.getElementById("wiki-md").innerHTML = result.page;
|
||||
} else if (typeof result.error !== "undefined") {
|
||||
document.getElementById("wiki-md-error").innerHTML = result.error
|
||||
}
|
||||
});
|
||||
}
|
||||
setTimeout(getWikiPage, 1000);');
|
||||
|
||||
return '<div id="wiki-md"><small>'.JText::_('COM_COMPONENTBUILDER_THE_WIKI_IS_LOADING').'.<span class="loading-dots">.</span></small></div><div id="wiki-md-error" style="color: red"></div>';
|
||||
}
|
||||
|
||||
|
||||
public function getGitea()
|
||||
{
|
||||
// get the document
|
||||
$document = JFactory::getDocument();
|
||||
// get the token if set
|
||||
$token = JComponentHelper::getParams('com_componentbuilder')->get('gitea_token', false);
|
||||
// only add if token is set
|
||||
if ($token)
|
||||
{
|
||||
// setup a registry
|
||||
$options = new Registry;
|
||||
$options->set('access.token', $token);
|
||||
// get the gitea http
|
||||
try
|
||||
{
|
||||
// get gitea object
|
||||
$gitea = new Gitea($options);
|
||||
// get a list of all the repos tags
|
||||
$tags = $gitea->repo->getListTags('joomla', 'Component-Builder');
|
||||
}
|
||||
catch (DomainException $m)
|
||||
{
|
||||
$token = false;
|
||||
}
|
||||
// get the document to load the scripts
|
||||
if ($token && isset($tags[0]) && isset($tags[0]->name))
|
||||
{
|
||||
// download link of the latest version
|
||||
$download = "https://git.vdm.dev/api/v1/repos/joomla/Component-Builder/archive/" . $tags[0]->name . ".zip?access_token=" . $token;
|
||||
// load the JavaScript to the page
|
||||
$document->addScriptDeclaration('
|
||||
jQuery(document).ready(function () {
|
||||
var activeVersion = "' . trim($tags[0]->name, 'vV') . '";
|
||||
if (activeVersion === manifest.version) {
|
||||
// local version is in sync with latest release
|
||||
jQuery(".update-notice").html("<small><span style=\'color:green;\'><span class=\'icon-shield\'></span>' . JText::_('COM_COMPONENTBUILDER_UP_TO_DATE') . '</span></small>");
|
||||
} else {
|
||||
// split versions in to array
|
||||
var activeVersionArray = activeVersion.split(".");
|
||||
var localVersionArray = manifest.version.split(".");
|
||||
if ((+localVersionArray[0] > +activeVersionArray[0]) ||
|
||||
(+localVersionArray[0] == +activeVersionArray[0] && +localVersionArray[1] > +activeVersionArray[1]) ||
|
||||
(+localVersionArray[0] == +activeVersionArray[0] && +localVersionArray[1] == +activeVersionArray[1] && +localVersionArray[2] > +activeVersionArray[2])) {
|
||||
// local version head latest release
|
||||
jQuery(".update-notice").html("<small><span style=\'color:#F7B033;\'><span class=\'icon-wrench\'></span>' . JText::_('COM_COMPONENTBUILDER_BETA_RELEASE') . '</span></small>");
|
||||
} else {
|
||||
// local version behind latest release
|
||||
jQuery(".update-notice").html("<small><span style=\'color:red;\'><span class=\'icon-warning-circle\'></span>' . JText::_('COM_COMPONENTBUILDER_OUT_OF_DATE') . '</span> <a style=\'color:green;\' href=\'' .
|
||||
$download . '\' title=\'' . JText::_('COM_COMPONENTBUILDER_YOU_CAN_DIRECTLY_DOWNLOAD_THE_LATEST_UPDATE_OR_USE_THE_JOOMLA_UPDATE_AREA') . '\'>' .
|
||||
JText::_('COM_COMPONENTBUILDER_DOWNLOAD_UPDATE') . '!</a></small>");
|
||||
}
|
||||
}
|
||||
});');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
// the URL
|
||||
$url = 'https://git.vdm.dev/user/settings/applications';
|
||||
// give a notice to get the token
|
||||
$document->addScriptDeclaration(
|
||||
'jQuery(document).ready(function () {jQuery(".update-notice").html("<small><a style=\'color:#F7B033;\' href=\'' .
|
||||
$url . '\' title=\'' . JText::_('COM_COMPONENTBUILDER_GET_TOKEN_FROM_VDM_FOR_UPDATES_AND_ADD_IT_TO_YOUR_GLOBAL_OPTIONS') . '\'>' .
|
||||
JText::_('COM_COMPONENTBUILDER_GET_TOKEN') . '!</a></small>");});'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getNoticeboard()
|
||||
{
|
||||
// get the document to load the scripts
|
||||
@ -590,5 +526,28 @@ jQuery(document).ready( function($) {
|
||||
});');
|
||||
|
||||
return '<div id="readme-md"><small>'.JText::_('COM_COMPONENTBUILDER_THE_README_IS_LOADING').'.<span class="loading-dots">.</span></small></div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function getVersion()
|
||||
{
|
||||
// the call URL
|
||||
$call_url = JUri::base() . 'index.php?option=com_componentbuilder&task=ajax.getVersion&format=json&raw=true&' . JSession::getFormToken() . '=1&version=1';
|
||||
$document = JFactory::getDocument();
|
||||
$document->addScriptDeclaration('
|
||||
function getComponentVersionStatus() {
|
||||
fetch("' . $call_url . '").then((response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
}).then((result) => {
|
||||
if (typeof result.notice !== "undefined") {
|
||||
document.getElementById("component-update-notice").innerHTML = result.notice;
|
||||
} else if (typeof result.error !== "undefined") {
|
||||
document.getElementById("component-update-notice").innerHTML = result.error;
|
||||
}
|
||||
});
|
||||
}
|
||||
setTimeout(getComponentVersionStatus, 800);');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user