Skip to content

Commit

Permalink
Feat: Versione 1.0.27 - Aggiornamento Validatore Versione 1.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-vernocchi committed Dec 6, 2024
1 parent 8d05e32 commit 2819c46
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 23 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pa-website-validator-ng-gui",
"version": "1.0.26",
"version": "1.0.27",
"main": "dist/main.js",
"type": "module",
"scripts": {
Expand All @@ -27,7 +27,7 @@
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"express": "^4.21.1",
"pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.9",
"pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.10",
"sqlite3": "^5.1.7",
"typeorm": "^0.3.20",
"yargs": "^17.7.2",
Expand Down
9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
cleanConsoleOutput,
AuditI,
getChromePath,
checkNewerRelease,
} from "./utils.js";
import { municipalityAudits, schoolAudits } from "./storage/auditMapping.js";
import { Item } from "./entities/Item";
Expand Down Expand Up @@ -134,6 +135,8 @@ const loadPage = async (
timeout?: string,
pages?: string,
) => {
const checkVersionResult = await checkNewerRelease();

const queryParam = url?.split("id=")[1];
const item = await getItemById(queryParam ?? "");
const mappedAuditsFailedObject: (
Expand Down Expand Up @@ -184,6 +187,12 @@ const loadPage = async (
const data = {
crawlerVersion: VERSION_VALIDATOR,
guiVersion: VERSION,
isLatestVersion: checkVersionResult?.isLatest,
latestVersion: checkVersionResult?.latestVersion,
latestVersionURL:
checkVersionResult?.isLatest == false
? checkVersionResult.latestVersionURL
: "",
basePathCss: path.join(__dirname, "public/css/"),
basePathJs: path.join(__dirname, "public/js/"),
basePathImages: path.join(__dirname, "public/images/"),
Expand Down
44 changes: 43 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { readFileSync, readdirSync, statSync } from "fs";
import path from "path";
import puppeteer from "puppeteer";
import { VERSION as currentVersion } from "./versions.js";

export interface AuditI {
text: string;
status: string;
}

const GITHUBReleaseUrl =
"https://api.github.com/repos/italia/pa-website-validator-gui/releases/latest";

let releaseInfo: null | any = null;

const getDataFromJSONReport = (reportPath: string) => {
let successCount = 0;
let failedCount = 0;
Expand Down Expand Up @@ -120,4 +126,40 @@ const getChromePath = () => {
}
};

export { getDataFromJSONReport, cleanConsoleOutput, getChromePath };
const checkNewerRelease = async () => {
if (releaseInfo) return releaseInfo;

try {
const response = await fetch(GITHUBReleaseUrl);
if (!response.ok) {
throw new Error(`GitHub API error: ${response.statusText}`);
}
const latestRelease = await response.json();
const latestVersion = latestRelease.tag_name;
const latestVersionURL = latestRelease.html_url;

const isLatest = currentVersion >= latestVersion.replace("v", "");

releaseInfo = {
isLatest,
currentVersion,
latestVersion,
latestVersionURL,
};
} catch (error) {
if (error instanceof Error) console.log(`${error.message}`);
releaseInfo = {
isLatest: true,
currentVersion,
};
}

return releaseInfo;
};

export {
getDataFromJSONReport,
cleanConsoleOutput,
getChromePath,
checkNewerRelease,
};
25 changes: 10 additions & 15 deletions src/views/partials/header.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<% if (!isLatestVersion ) { %>
<div class="alert alert-warning mb-0" role="alert">
E' disponibile una nuova versione dell'app di valutazione! <a href="<%- latestVersionURL %>" class="alert-link" target="_blank" rel="noopener noreferrer">Puoi scaricarla qui: <%- latestVersion %></a>.
</div>
<% } %>
<header class="it-header-wrapper mb-4">
<%- include('components/skip-links'); %>
<div class="it-nav-wrapper container">
Expand All @@ -8,15 +13,14 @@
<div class="it-header-center-content-wrapper">
<div class="it-brand-wrapper">
<a>
<img class="border border-white me-2 me-lg-3" src="<%- basePathImages %>dtd_logo.png" alt=""
width="48" height="48">
<img class="border border-white me-2 me-lg-3" src="<%- basePathImages %>dtd_logo.png" alt="" width="48" height="48">
<div class="it-brand-text">
<div class="it-brand-title h4">
App di valutazione
</div>
</div>
</a>
</div>
</div class=" text-white">
<div class="it-right-zone">
<p>Versione GUI: <%- guiVersion %></p>
<p>Versione validatore: <%- crawlerVersion %></p>
Expand All @@ -32,9 +36,7 @@
<div class="col-12">
<!--start nav-->
<nav class="navbar navbar-expand-lg" aria-label="Navigazione principale">
<button class="custom-navbar-toggler" type="button" aria-controls="headerNav" aria-expanded="false"
aria-label="Mostra/Nascondi la navigazione" data-bs-toggle="navbarcollapsible"
data-bs-target="#headerNav">
<button class="custom-navbar-toggler" type="button" aria-controls="headerNav" aria-expanded="false" aria-label="Mostra/Nascondi la navigazione" data-bs-toggle="navbarcollapsible" data-bs-target="#headerNav">
<svg class="icon">
<use href="#it-burger"></use>
</svg>
Expand All @@ -52,19 +54,12 @@
<div class="menu-wrapper">
<ul class="navbar-nav">
<li class="nav-item <%- currentPage === 'home' ? 'active' : '' %>">
<a class="nav-link <%- currentPage === 'home' ? 'active' : '' %> <%- currentPage === 'scanning' ? 'disabled' : '' %>"
data-page="home" href="/home" aria-current="<%- currentPage === 'home' ? 'page' : 'false' %>"
aria-disabled="<%- currentPage === 'scanning' ? 'true' : 'false' %>"
tabindex="<%- currentPage === 'scanning' ? '-1' : '0' %>">
<a class="nav-link <%- currentPage === 'home' ? 'active' : '' %> <%- currentPage === 'scanning' ? 'disabled' : '' %>" data-page="home" href="/home" aria-current="<%- currentPage === 'home' ? 'page' : 'false' %>" aria-disabled="<%- currentPage === 'scanning' ? 'true' : 'false' %>" tabindex="<%- currentPage === 'scanning' ? '-1' : '0' %>">
Nuova scansione
</a>
</li>
<li class="nav-item <%- currentPage === 'history' ? 'active' : '' %>">
<a class="nav-link <%- currentPage === 'history' ? 'active' : '' %> <%- currentPage === 'scanning' ? 'disabled' : '' %>"
data-page="history" href="/history"
aria-current="<%- currentPage === 'history' ? 'page' : 'false' %>"
aria-disabled="<%- currentPage === 'scanning' ? 'true' : 'false' %>"
tabindex="<%- currentPage === 'scanning' ? '-1' : '0' %>">
<a class="nav-link <%- currentPage === 'history' ? 'active' : '' %> <%- currentPage === 'scanning' ? 'disabled' : '' %>" data-page="history" href="/history" aria-current="<%- currentPage === 'history' ? 'page' : 'false' %>" aria-disabled="<%- currentPage === 'scanning' ? 'true' : 'false' %>" tabindex="<%- currentPage === 'scanning' ? '-1' : '0' %>">
Storico scansioni
</a>
</li>
Expand Down

0 comments on commit 2819c46

Please sign in to comment.