Add clickable names to go to repos

This commit is contained in:
BlipRanger
2023-07-12 23:54:17 -04:00
parent cc7c42232e
commit eccae1056f
3 changed files with 57 additions and 39 deletions

View File

@@ -382,25 +382,35 @@ async function generateExtensionHtml(name, manifest, isActive, isDisabled, isExt
const displayName = manifest.display_name; const displayName = manifest.display_name;
let displayVersion = manifest.version ? ` v${manifest.version}` : ""; let displayVersion = manifest.version ? ` v${manifest.version}` : "";
let isUpToDate = true; let isUpToDate = true;
let updateButton = '';
let originHtml = '';
if (isExternal) { if (isExternal) {
let data = await getExtensionVersion(name.replace('third-party', '')); let data = await getExtensionVersion(name.replace('third-party', ''));
let branch = data.currentBranchName; let branch = data.currentBranchName;
let commitHash = data.currentCommitHash; let commitHash = data.currentCommitHash;
let origin = data.remoteUrl
isUpToDate = data.isUpToDate; isUpToDate = data.isUpToDate;
displayVersion = ` (${branch}-${commitHash.substring(0, 7)})`; displayVersion = ` (${branch}-${commitHash.substring(0, 7)})`;
updateButton = isUpToDate ?
`<span class="update-button"><button class="btn_update menu_button" data-name="${name.replace('third-party', '')}" title="Up to date"><i class="fa-solid fa-code-commit"></i></button></span>` :
`<span class="update-button"><button class="btn_update menu_button" data-name="${name.replace('third-party', '')}" title="Update available"><i class="fa-solid fa-download"></i></button></span>`;
originHtml = `<a href="${origin}" target="_blank" rel="noopener noreferrer">`;
} }
let toggleElement = isActive || isDisabled ? let toggleElement = isActive || isDisabled ?
`<input type="checkbox" title="Click to toggle" data-name="${name}" class="${isActive ? 'toggle_disable' : 'toggle_enable'} ${checkboxClass}" ${isActive ? 'checked' : ''}>` : `<input type="checkbox" title="Click to toggle" data-name="${name}" class="${isActive ? 'toggle_disable' : 'toggle_enable'} ${checkboxClass}" ${isActive ? 'checked' : ''}>` :
`<input type="checkbox" title="Cannot enable extension" data-name="${name}" class="extension_missing ${checkboxClass}" disabled>`; `<input type="checkbox" title="Cannot enable extension" data-name="${name}" class="extension_missing ${checkboxClass}" disabled>`;
let updateButton = isExternal && !isUpToDate ? `<button class="btn_update" data-name="${name.replace('third-party', '')}">Update</button>` : ''; // if external, wrap the name in a link to the repo
let extensionHtml = `<hr> let extensionHtml = `<hr>
<h4> <h4>
<span class="update-button">${updateButton}</span> ${updateButton}
${originHtml}
<span class="${isActive ? "extension_enabled" : isDisabled ? "extension_disabled" : "extension_missing"}"> <span class="${isActive ? "extension_enabled" : isDisabled ? "extension_disabled" : "extension_missing"}">
${DOMPurify.sanitize(displayName)}${displayVersion} ${DOMPurify.sanitize(displayName)}${displayVersion}
</span> </span>
${isExternal ? '</a>' : ''}
<span style="float:right;">${toggleElement}</span> <span style="float:right;">${toggleElement}</span>
</h4>`; </h4>`;
@@ -488,8 +498,7 @@ async function onUpdateClick() {
console.log('Extension updated'); console.log('Extension updated');
toastr.success(`Extension updated to ${data.shortCommitHash}`); toastr.success(`Extension updated to ${data.shortCommitHash}`);
} }
$(this).text(data.shortCommitHash); showExtensionsDetails();
console.log(data);
} catch (error) { } catch (error) {
console.error('Error:', error); console.error('Error:', error);
} }

View File

@@ -3804,7 +3804,7 @@ input.extension_missing[type="checkbox"] {
.update-button { .update-button {
margin-right: 10px; margin-right: 10px;
/* Adjust the value as needed */ display: inline-flex;
} }
/* possible place for WI Entry header styling */ /* possible place for WI Entry header styling */

View File

@@ -4399,10 +4399,17 @@ async function checkIfRepoIsUpToDate(extensionPath) {
to: `origin/${currentBranch.current}`, to: `origin/${currentBranch.current}`,
}); });
return log.total === 0; // Fetch remote repository information
const remotes = await git.cwd(extensionPath).getRemotes(true);
return {
isUpToDate: log.total === 0,
remoteUrl: remotes[0].refs.fetch, // URL of the remote repository
};
} }
/** /**
* HTTP POST handler function to clone a git repository from a provided URL, read the extension manifest, * HTTP POST handler function to clone a git repository from a provided URL, read the extension manifest,
* and return extension information and path. * and return extension information and path.
@@ -4462,19 +4469,20 @@ app.post('/update_extension', jsonParser, async (request, response) => {
return response.status(404).send(`Directory does not exist at ${extensionPath}`); return response.status(404).send(`Directory does not exist at ${extensionPath}`);
} }
const isUpToDate = await checkIfRepoIsUpToDate(extensionPath); const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath);
const currentBranch = await git.cwd(extensionPath).branch();
if (!isUpToDate) { if (!isUpToDate) {
await git.cwd(extensionPath).pull('origin', currentBranch.current); await git.cwd(extensionPath).pull('origin', currentBranch.current);
console.log(`Extension has been updated at ${extensionPath}`); console.log(`Extension has been updated at ${extensionPath}`);
} else { } else {
console.log(`Extension is up to date at ${extensionPath}`); console.log(`Extension is up to date at ${extensionPath}`);
} }
await git.cwd(extensionPath).fetch('origin');
const fullCommitHash = await git.cwd(extensionPath).revparse(['HEAD']); const fullCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
const shortCommitHash = fullCommitHash.slice(0, 7); const shortCommitHash = fullCommitHash.slice(0, 7);
return response.send({ shortCommitHash, extensionPath, isUpToDate: isUpToDate.total === 0 }); return response.send({ shortCommitHash, extensionPath, isUpToDate, remoteUrl });
} catch (error) { } catch (error) {
console.log('Updating custom content failed', error); console.log('Updating custom content failed', error);
@@ -4501,11 +4509,12 @@ app.post('/get_extension_version', jsonParser, async (request, response) => {
const currentBranch = await git.cwd(extensionPath).branch(); const currentBranch = await git.cwd(extensionPath).branch();
// get only the working branch // get only the working branch
const currentBranchName = currentBranch.current; const currentBranchName = currentBranch.current;
await git.cwd(extensionPath).fetch('origin');
const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']); const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
console.log(currentBranch, currentCommitHash); console.log(currentBranch, currentCommitHash);
const isUpToDate = await checkIfRepoIsUpToDate(extensionPath); const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath);
return response.send({ currentBranchName, currentCommitHash, isUpToDate }); return response.send({ currentBranchName, currentCommitHash, isUpToDate, remoteUrl });
} catch (error) { } catch (error) {
console.log('Getting extension version failed', error); console.log('Getting extension version failed', error);