Skip to content

Commit

Permalink
Some refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
ahzf committed Apr 15, 2024
1 parent 0ea6c12 commit 0d33312
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 50 deletions.
5 changes: 1 addition & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
connect-src 'self'
https://chargy.charging.cloud
https://open.charging.cloud/chargy/
https://lichtblick.c.charging.cloud/chargy/
https://raw.githubusercontent.com/OpenChargingCloud/ChargyDesktopApp/master/;
img-src 'self' data: https:;
script-src 'self' 'unsafe-inline' 'unsafe-eval';
Expand Down Expand Up @@ -105,7 +104,7 @@
<div id="openSourceLibs">

<div class="lib">
<div class="name">Chargy Web App<span id="chargyVersion"></span></div>
<div class="name">Chargy WebApp<span id="chargyVersion"></span></div>
<div class="license"><button class="linkButton" href="https://github.com/OpenChargingCloud/ChargyWebApp/blob/master/LICENSE">Copyright &copy; 2018-2024 GraphDefined GmbH<br />AGPL v3 License</button></div>
</div>
<div class="lib">
Expand Down Expand Up @@ -271,8 +270,6 @@

</div>

<div id="clear"></div>

</div>

<div id="overlay">
Expand Down
3 changes: 3 additions & 0 deletions src/scss/chargy.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ body {

#feedback {

display: none;
width: 100%;
padding: 20px 20px 40px 20px;
width: calc(100% - 40px);
Expand Down Expand Up @@ -1424,13 +1425,15 @@ body {
}

#eMail {
display: none;
i {
position: relative;
top: 1px;
}
}

#hotline {
display: none;
i {
position: relative;
top: 2px;
Expand Down
115 changes: 69 additions & 46 deletions src/ts/chargyApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@
* limitations under the License.
*/

import * as path from 'path';
import { Chargy } from './chargy'
import * as chargyInterfaces from './chargyInterfaces'
import * as chargyLib from './chargyLib'

import Decimal from 'decimal.js';
import * as L from 'leaflet';
import Decimal from 'decimal.js';
import '../scss/chargy.scss';

// import { debug } from "util";
// import * as crypto from "crypto";
// import { readSync } from "fs";
// import { version } from "punycode";

export class ChargyApp {

//#region Data
Expand All @@ -44,18 +37,13 @@ export class ChargyApp {

public appEdition: string = "";
public copyright: string = "";
public appVersion: string = "";
public versionsURL: string = "";
public defaultFeedbackEMail: string[] = [];
public defaultFeedbackHotline: string[] = [];
public defaultIssueURL: string = "";
//private ipcRenderer = require('electron').ipcRenderer; // (window as any)?.electron?.ipcRenderer;
//private commandLineArguments: Array<string> = [];
public packageJson: any = {};
public i18n: any = {};
public UILanguage: string = "de";
// private httpPort: number = 0;
// private httpHost: string = "localhost";

private currentAppInfos: any = null;
private currentVersionInfos: any = null;
Expand Down Expand Up @@ -117,12 +105,44 @@ export class ChargyApp {

//#endregion

constructor(versionsURL?: string,
constructor(appEdition?: string,
copyright?: string,
versionsURL?: string,
showFeedbackSection?: Boolean,
feedbackEMail?: string[],
feedbackHotline?: string[],
issueURL?: string) {

//#region Set parameters

this.appEdition = appEdition ?? "";
this.copyright = copyright ?? "";
this.versionsURL = versionsURL ?? "https://open.charging.cloud/desktop/versions";
this.showFeedbackSection = showFeedbackSection ?? false;
this.defaultFeedbackEMail = feedbackEMail ?? [];
this.defaultFeedbackHotline = feedbackHotline ?? [];
this.defaultIssueURL = issueURL ?? "";

//#endregion

//#region Load external data from web server

this.loadI18n();
this.loadPackageJSON();

//#endregion

//#region Load external data from file system

this.elliptic = require('elliptic');
this.moment = require('moment');
this.asn1 = require('asn1.js');
this.base32Decode = require('base32-decode')

//#endregion

//#region Set up the GUI

this.appDiv = document.getElementById('app') as HTMLDivElement;
this.headlineDiv = document.getElementById('headline') as HTMLDivElement;
this.verifyframeDiv = document.getElementById('verifyframe') as HTMLDivElement;
Expand All @@ -139,7 +159,6 @@ export class ChargyApp {
this.applicationHashDiv = document.getElementById('applicationHash') as HTMLDivElement;
this.applicationHashValueDiv = this.applicationHashDiv.querySelector("#value") as HTMLDivElement;

this.showFeedbackSection = showFeedbackSection ?? false;
this.feedbackDiv = document.getElementById('feedback') as HTMLDivElement;
this.feedbackMethodsDiv = this.feedbackDiv. querySelector("#feedbackMethods") as HTMLDivElement;
this.showIssueTrackerButton = this.feedbackMethodsDiv.querySelector("#showIssueTracker") as HTMLButtonElement;
Expand Down Expand Up @@ -173,18 +192,7 @@ export class ChargyApp {
this.exportButtonDiv = document.getElementById('exportButtonDiv') as HTMLDivElement;
this.exportButton = this.exportButtonDiv. querySelector("#exportButton") as HTMLButtonElement;

this.versionsURL = versionsURL ?? "https://open.charging.cloud/chargy/desktop/versions";
this.defaultIssueURL = issueURL ?? "https://open.charging.cloud/chargy/desktop/issues";
this.defaultFeedbackEMail = feedbackEMail != undefined ? feedbackEMail : ["[email protected]", "?subject=Chargy%20Support"];
this.defaultFeedbackHotline = feedbackHotline != undefined ? feedbackHotline : ["+491728930852", "+49 172 8930852"];

this.loadI18n();
this.loadPackageJSON();

this.elliptic = require('elliptic');
this.moment = require('moment');
this.asn1 = require('asn1.js');
this.base32Decode = require('base32-decode')
//#endregion

this.chargy = new Chargy(this.i18n,
this.UILanguage,
Expand Down Expand Up @@ -236,7 +244,7 @@ export class ChargyApp {
let data:any = {};

data["timestamp"] = new Date().toISOString();
data["chargyVersion"] = this.appVersion;
data["chargyVersion"] = this.packageJson.version;
data["platform"] = process.platform;

data["invalidCTR"] = (newIssueForm.querySelector("#invalidCTR") as HTMLInputElement).checked;
Expand Down Expand Up @@ -625,13 +633,13 @@ export class ChargyApp {
const data = await response.json();
Object.assign(this.packageJson, data);

//#region Set infos of the about section
//#region Set infos of the about section

(this.softwareInfosDiv. querySelector("#appEdition") as HTMLSpanElement).innerHTML = this.appEdition;
(this.softwareInfosDiv. querySelector("#appVersion") as HTMLSpanElement).innerHTML = this.appVersion;
(this.softwareInfosDiv. querySelector("#appVersion") as HTMLSpanElement).innerHTML = this.packageJson.version;
(this.softwareInfosDiv. querySelector("#copyright") as HTMLSpanElement).innerHTML = this.copyright;

(this.openSourceLibsDiv.querySelector("#chargyVersion") as HTMLSpanElement).innerHTML = this.appVersion;
(this.openSourceLibsDiv.querySelector("#chargyVersion") as HTMLSpanElement).innerHTML = this.packageJson.version;

if (this.packageJson.devDependencies)
{
Expand Down Expand Up @@ -684,11 +692,19 @@ export class ChargyApp {

//#region Issue Tracker

this.showIssueTrackerButton.onclick = (ev: MouseEvent) => {
this.issueTrackerDiv.style.display = 'block';
this.privacyStatement.style.display = "none";
this.issueTrackerText.scrollTop = 0;
if (this.defaultIssueURL !== "")
{

this.showIssueTrackerButton.style.display = "block";

this.showIssueTrackerButton.onclick = (ev: MouseEvent) => {
this.issueTrackerDiv.style.display = 'block';
this.privacyStatement.style.display = "none";
this.issueTrackerText.scrollTop = 0;
}
}
else
this.showIssueTrackerButton.style.display = "none";

//#endregion

Expand All @@ -698,9 +714,12 @@ export class ChargyApp {

if (feedbackEMail && feedbackEMail.length == 2)
{
this.feedbackEMailAnchor.href = "mailto:" + feedbackEMail[0] + feedbackEMail[1];
this.feedbackEMailAnchor.innerHTML += feedbackEMail[0];
this.feedbackEMailAnchor.style.display = "block";
this.feedbackEMailAnchor.href = "mailto:" + feedbackEMail[0] + feedbackEMail[1];
this.feedbackEMailAnchor.innerHTML += feedbackEMail[0];
}
else
this.feedbackEMailAnchor.style.display = "none";

//#endregion

Expand All @@ -710,9 +729,12 @@ export class ChargyApp {

if (feedbackHotline && feedbackHotline.length == 2)
{
this.feedbackHotlineAnchor.href = "tel:" + feedbackHotline[0];
this.feedbackHotlineAnchor.innerHTML += feedbackHotline[1];
this.feedbackHotlineAnchor.style.display = "block";
this.feedbackHotlineAnchor.href = "tel:" + feedbackHotline[0];
this.feedbackHotlineAnchor.innerHTML += feedbackHotline[1];
}
else
this.feedbackHotlineAnchor.style.display = "none";

//#endregion

Expand Down Expand Up @@ -980,7 +1002,7 @@ export class ChargyApp {
"description": app.description,

"version": {
"version": this.appVersion,
"version": this.packageJson.version,
"releaseDate": version.releaseDate,
"description": version.description,
"tags": version.tags,
Expand Down Expand Up @@ -2671,14 +2693,15 @@ export class ChargyApp {
// Remember to set Content-Security-Policy for customer support URLs!
// Remember to set Customer Privacy Statement!
// Remember to set Customer Mapbox Access Token and MapId!
// Remember to set the "applicationEdition" in main.cjs

const app = new ChargyApp(
"https://lichtblick.c.charging.cloud/chargy/desktop/versions", //"https://raw.githubusercontent.com/OpenChargingCloud/ChargyDesktopApp/master/versions/versions.json",
false, // Show Feedback Section
["[email protected]", "?subject=Chargy%20Support"],
["+4993219319101", "+49 9321 9319 101"],
"https://lichtblick.c.charging.cloud/chargy/desktop/issues"
"",
"&copy; 2018-2024 GraphDefined GmbH",
"https://chargy.charging.cloud/desktop/versions", //"https://raw.githubusercontent.com/OpenChargingCloud/ChargyDesktopApp/master/versions/versions.json",
true, // Show Feedback Section
["[email protected]", "?subject=Chargy%20WebApp%20Support"],
undefined, //["+4993219319101", "+49 9321 9319 101"],
"https://chargy.charging.cloud/desktop/issues"
);

// const app = new ChargyApp("https://chargepoint.charging.cloud/chargy/versions", //"https://raw.githubusercontent.com/OpenChargingCloud/ChargyDesktopApp/master/versions/versions.json",
Expand Down

0 comments on commit 0d33312

Please sign in to comment.