Skip to content

Commit

Permalink
SonarCloud: suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rugoncalves committed Oct 8, 2024
1 parent 3111d1c commit 505f15b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 57 deletions.
42 changes: 21 additions & 21 deletions src/OSFramework/Maps/ProviderVersion.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace OSFramework.Maps.ProviderVersion {
/**
* Function that allows to get the version of a specific the provider
* Function that allows to set the version of a specific the provider.
* If the forceRefresh is set to true and the version has changed, the page will be reloaded.
* Otherwise, the version will be updated in the local storage.
*
* @export
* @param {OSFramework.Maps.Enum.ProviderType} provider
* @return {*} {string}
* @param {string} version
* @param {boolean} [forceRefresh=false]
*/
export function Get(provider: OSFramework.Maps.Enum.ProviderType): string {
let version = '';
export function Change(provider: OSFramework.Maps.Enum.ProviderType, version: string, forceRefresh = false): void {
let versionChanged = false;
switch (provider) {
case OSFramework.Maps.Enum.ProviderType.Google:
version = Provider.Maps.Google.Version.Get();
versionChanged = Provider.Maps.Google.Version.Change(version);
break;
case OSFramework.Maps.Enum.ProviderType.Leaflet:
version = Provider.Maps.Leaflet.Version.Get();
versionChanged = Provider.Maps.Leaflet.Version.Change(version);
break;
default:
throw new Error(`There provider '${provider}' is not supported.`);
}
return version;

if (forceRefresh && versionChanged) {
// Force refresh the library
window.location.reload();
}
}

/**
* Function that allows to set the version of a specific the provider.
* If the forceRefresh is set to true and the version has changed, the page will be reloaded.
* Otherwise, the version will be updated in the local storage.
* Function that allows to get the version of a specific the provider
*
* @export
* @param {OSFramework.Maps.Enum.ProviderType} provider
* @param {string} version
* @param {boolean} [forceRefresh=false]
* @return {*} {string}
*/
export function Set(provider: OSFramework.Maps.Enum.ProviderType, version: string, forceRefresh = false): void {
let versionChanged = false;
export function Get(provider: OSFramework.Maps.Enum.ProviderType): string {
let version = '';
switch (provider) {
case OSFramework.Maps.Enum.ProviderType.Google:
versionChanged = Provider.Maps.Google.Version.Set(version);
version = Provider.Maps.Google.Version.Get();
break;
case OSFramework.Maps.Enum.ProviderType.Leaflet:
versionChanged = Provider.Maps.Leaflet.Version.Set(version);
version = Provider.Maps.Leaflet.Version.Get();
break;
default:
throw new Error(`There provider '${provider}' is not supported.`);
}

if (forceRefresh && versionChanged) {
// Force refresh the library
window.location.reload();
}
return version;
}
}
2 changes: 1 addition & 1 deletion src/OutSystems/Maps/MapAPI/LibraryVersioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace OutSystems.Maps.MapAPI.ProviderLibrary {
version: string,
forceRefresh = false
): void {
OSFramework.Maps.ProviderVersion.Set(provider, version, forceRefresh);
OSFramework.Maps.ProviderVersion.Change(provider, version, forceRefresh);
}
}
46 changes: 23 additions & 23 deletions src/Providers/Maps/Google/Version/Version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ namespace Provider.Maps.Google.Version {
return version;
}

/**
* Set the version of Google Maps to be used on the page.
*
* @export
* @param {string} newVersion
* @return {*} {boolean}
*/
export function Change(newVersion: string): boolean {
const currentVersion =
OSFramework.Maps.Helper.LocalStorage.GetItem(Constants.googleMapsLocalStorageVersionKey) ||
Constants.googleMapsVersion;

const googleVersion = GetGoogleMapsVersion();

// If the version that the developer set is different from the current version, and is different from the version loaded, set the return value to true.
const versionChanged = currentVersion !== newVersion && newVersion !== googleVersion;

OSFramework.Maps.Helper.LocalStorage.SetItem(Constants.googleMapsLocalStorageVersionKey, newVersion);

return versionChanged;
}

/**
* Get the current version of Google Maps loaded on the page.
*
Expand All @@ -30,33 +52,11 @@ namespace Provider.Maps.Google.Version {
// If the version that the developer set is still not being used, log a warning message and return the current loaded version.
if (googleVersion !== undefined && currentVersion !== googleVersion) {
OSFramework.Maps.Helper.LogWarningMessage(
`Current version of Google Maps loaded is '${googleVersion}', but on the next page refresh the version will be '${currentVersion}'.`
`Current version of Google Maps loaded is '${googleVersion}', but on the next page refresh the version will tentatively be '${currentVersion}'.`
);
currentVersion = googleVersion;
}

return currentVersion;
}

/**
* Set the version of Google Maps to be used on the page.
*
* @export
* @param {string} newVersion
* @return {*} {boolean}
*/
export function Set(newVersion: string): boolean {
const currentVersion =
OSFramework.Maps.Helper.LocalStorage.GetItem(Constants.googleMapsLocalStorageVersionKey) ||
Constants.googleMapsVersion;

const googleVersion = GetGoogleMapsVersion();

// If the version that the developer set is different from the current version, and is different from the version loaded, set the return value to true.
const versionChanged = currentVersion !== newVersion && newVersion !== googleVersion;

OSFramework.Maps.Helper.LocalStorage.SetItem(Constants.googleMapsLocalStorageVersionKey, newVersion);

return versionChanged;
}
}
26 changes: 14 additions & 12 deletions src/Providers/Maps/Leaflet/Version/Version.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace Provider.Maps.Leaflet.Version {
/**
* Get the current version of Google Maps loaded on the page.
*
* @export
* @return {*} {string}
*/
export function Get(): string {
return Constants.leafletVersion;
}

/**
* Set the version of Google Maps to be used on the page.
* Currently, changing the version of Leaflet is not supported.
Expand All @@ -19,8 +9,20 @@ namespace Provider.Maps.Leaflet.Version {
* @return {*} {boolean}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function Set(newVersion: string): boolean {
OSFramework.Maps.Helper.LogWarningMessage('Changing Leaflet version is not supported');
export function Change(newVersion: string): boolean {
OSFramework.Maps.Helper.LogWarningMessage(
`Changing Leaflet version is not supported. Using version '${Constants.leafletVersion}'.`
);
return false;
}

/**
* Get the current version of Google Maps loaded on the page.
*
* @export
* @return {*} {string}
*/
export function Get(): string {
return Constants.leafletVersion;
}
}

0 comments on commit 505f15b

Please sign in to comment.