Skip to content

Commit

Permalink
Outsourced some code to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenMuellauer committed Oct 24, 2024
1 parent 6fa0d19 commit 171666a
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 177 deletions.
145 changes: 72 additions & 73 deletions UI5_Quality_Checks_App/webapp/controller/startpage.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {

SRBInfoAndSupport.init(this.getOwnerComponent());

this.currentPage = 1;
this.resultsModel = new sap.ui.model.json.JSONModel({
results: []
});
},

/**
Expand All @@ -49,45 +51,50 @@ sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {
});
},

setResultData: function (resultRecord, versionInfo, fileContent, isMin) {
var problematic = false;
startPressed: async function () {
var that = this;
var userNameLabel = this.getView().byId("usernameLabel");
var userAvatar = this.getView().byId("myAvatar");
var loginBox = this.getView().byId("loginBox");

resultRecord["fileContent"] = fileContent;
resultRecord["version"] = versionInfo.version;
resultRecord["isMinVersion"] = isMin;
var filterPanel = this.getView().byId("filterPanel");
var resultsTable = this.getView().byId("resultsTable");

// else resultRecord["version"] = `mind. ${versionInfo.version}`;
resultRecord["isEvergreenBootstrap"] = versionInfo.isEvergreenBootstrap;
resultRecord["eocp"] = versionInfo.eocp;
resultRecord["eom"] = versionInfo.eom;
resultRecord["detected"] = versionInfo.detected;
sap.ui.core.BusyIndicator.show(0);

// console.log(resultRecord);
if (versionInfo.eocp === "removed") {
//<-- This version is out of maintainance
problematic = true;
}
resultsTable.setModel(that.resultsModel);

if (versionInfo.isEvergreenBootstrap !== true) {
//<-- This version is out of maintainance
problematic = true;
}
var tokenInput = this.getView().byId("tokenInput");
var tokenValue = tokenInput.getValue().trim();

resultRecord["problematic"] = problematic;
await SRBGitHub.setup(tokenValue);
var userData = await SRBGitHub.getLoginData();

return resultRecord;
userNameLabel.setText(userData.login);
userAvatar.setSrc(userData.avatar_url);

filterPanel.setVisible(true);
resultsTable.setVisible(true);
loginBox.setVisible(false);

this.fetchData();
},

fetchLinterStatus: async function () {},

Check failure on line 83 in UI5_Quality_Checks_App/webapp/controller/startpage.controller.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

Unexpected empty async method 'fetchLinterStatus'

fetchData: async function (resultsModel) {
fetchData: async function () {
var that = this;
var { results, headers } = await SRBGitHub.getUI5BootstrappingFiles(that.currentPage);
var noVersionFound = [];
var minVersions = [];

console.log(headers);
var { results, headers } = await SRBGitHub.getUI5BootstrappingFiles();
var noVersionsFound = await that.fetchIndexData(results);

var { result: manifestFiles } = await SRBGitHub.getUI5ManifestFile(noVersionsFound);
await that.fetchManifestData(manifestFiles);
},

fetchIndexData: async function (results) {
var that = this;
var noVersionFound = [];
for (const repoResult of results) {
var resultRecord = {
repo: repoResult.repository.name,
Expand All @@ -102,14 +109,16 @@ sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {

if (version.isMinVersion === true) {
noVersionFound.push(repoResult.repository.name);
minVersions.push(version);
} else {
that.setResultData(resultRecord, version, file, false);
that.addRow(resultsModel, resultRecord);
that.addRow(resultRecord);
}
}
return noVersionFound;
},

var { result: manifestFiles } = await SRBGitHub.getUI5ManifestFile(noVersionFound);
fetchManifestData: async function (manifestFiles) {
var that = this;
for (const manifestResult of manifestFiles) {
var resultRecord = {
repo: manifestResult.repository.name,
Expand All @@ -126,63 +135,53 @@ sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {
version.version = minVersion;

if (version.isEvergreenBootstrap === true) {
var versionCheck = SRBGitHub.checkForVersionSupport(undefined, minVersion);
version.eocp = versionCheck.eocp;
version.eom = versionCheck.eom;
var { eocp, eom } = SRBGitHub.checkForVersionSupport(undefined, minVersion);
version.eocp = eocp;
version.eom = eom;
} else {
var patchCheck = SRBGitHub.checkForPatchSupport(undefined, minVersion);
if (patchCheck) {
version.eocp = patchCheck.eocp;
version.eom = patchCheck.eom;
}
var { eocp, eom } = SRBGitHub.checkForPatchSupport(undefined, minVersion);

Check failure on line 142 in UI5_Quality_Checks_App/webapp/controller/startpage.controller.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

'eocp' is already defined

Check failure on line 142 in UI5_Quality_Checks_App/webapp/controller/startpage.controller.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

'eom' is already defined
version.eocp = eocp;
version.eom = eom;
}
that.setResultData(resultRecord, version, file, true);

that.addRow(resultsModel, resultRecord);
that.addRow(resultRecord);
}
that.currentPage++;
},

addRow: function (resultsModel, resultRecord) {
var tableData = resultsModel.getProperty("/results");
if (tableData.map(({ fileUrl }) => fileUrl).includes(resultRecord["fileUrl"]) === false) {
tableData.push(resultRecord);
resultsModel.setProperty("/results", tableData);
sap.ui.core.BusyIndicator.hide();
}
},

startPressed: async function () {
var that = this;
var userNameLabel = this.getView().byId("usernameLabel");
var userAvatar = this.getView().byId("myAvatar");
var loginBox = this.getView().byId("loginBox");

var filterPanel = this.getView().byId("filterPanel");
var resultsTable = this.getView().byId("resultsTable");

var resultsModel = new sap.ui.model.json.JSONModel({
results: []
});
setResultData: function (resultRecord, versionInfo, fileContent, isMin) {
var problematic = false;

sap.ui.core.BusyIndicator.show(0);
resultRecord["fileContent"] = fileContent;
resultRecord["version"] = versionInfo.version;
resultRecord["isMinVersion"] = isMin;

resultsTable.setModel(resultsModel);
resultRecord["isEvergreenBootstrap"] = versionInfo.isEvergreenBootstrap;
resultRecord["eocp"] = versionInfo.eocp;
resultRecord["eom"] = versionInfo.eom;
resultRecord["detected"] = versionInfo.detected;

var tokenInput = this.getView().byId("tokenInput");
var tokenValue = tokenInput.getValue().trim();
if (versionInfo.eocp === "removed") {
problematic = true;
}

await SRBGitHub.setup(tokenValue);
var userData = await SRBGitHub.getLoginData();
if (versionInfo.isEvergreenBootstrap !== true) {
problematic = true;
}

userNameLabel.setText(userData.login);
userAvatar.setSrc(userData.avatar_url);
resultRecord["problematic"] = problematic;

filterPanel.setVisible(true);
resultsTable.setVisible(true);
loginBox.setVisible(false);
return resultRecord;
},

this.fetchData(resultsModel);
addRow: function (resultRecord) {
var that = this;
var tableData = that.resultsModel.getProperty("/results");
if (tableData.map(({ fileUrl }) => fileUrl).includes(resultRecord["fileUrl"]) === false) {
tableData.push(resultRecord);
that.resultsModel.setProperty("/results", tableData);
sap.ui.core.BusyIndicator.hide();
}
},

showSupportDialogPressed: function () {
Expand Down
92 changes: 9 additions & 83 deletions UI5_Quality_Checks_App/webapp/libs/SRBGitHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var SRBGitHub = (function () {
return response.data;
},

getUI5BootstrappingFiles: async function (page) {
getUI5BootstrappingFiles: async function () {
var that = this;

checkSetup();
Expand All @@ -38,14 +38,13 @@ var SRBGitHub = (function () {
q: cdnAQuery,
type: "code",
// eslint-disable-next-line camelcase
per_page: 100,
page: page
per_page: 100
});

return { results: response.data.items, headers: response.headers };
},

getUI5ManifestFile: async function (repos, page) {
getUI5ManifestFile: async function (repos) {
var that = this;

checkSetup();
Expand Down Expand Up @@ -77,77 +76,6 @@ var SRBGitHub = (function () {
return atob(response.data.content);
},

detectUI5VersionInFile: function (fileContentText, repo) {
var that = this;

checkSetup();

return new Promise(function (resolve, reject) {
var overviewData = availableVersionsModel.getData();
var patches = overviewData.patches;
var versions = overviewData.versions;

var detected = false;
var evergreen = false;
var eocp;
var eom;

var groups = [];
var versionString;

groups = fileContentText.match("https://sapui5.hana.ondemand.com/(.*)(/resources)");

if (groups) {
versionString = groups[1];
detected = true;
} else {
groups = fileContentText.match("https://ui5.sap.com/(.*)(/resources)");

if (groups) {
versionString = groups[1];
detected = true;
} else {
console.log("Hello");
}
}

if (versionString) {
evergreen = versionString.split(".").length <= 2;
}

if (evergreen === true) {
versions.forEach(function (versionEntry) {
var major = versionEntry.version.split(".")[0];
var minor = versionEntry.version.split(".")[1];
var compareVersion = major + "." + minor;

if (versionString === compareVersion) {
eocp = versionEntry.eocp;
eom = versionEntry.eom;
}
});
} else {
patches.forEach(function (patch) {
if (patch.version === versionString) {
if (patch.removed === true) {
eocp = "reached"; // <-- Write true because it has beed removed
} else {
eocp = patch.eocp === true ? "reached" : patch.eocp; // <-- Write the provided eocp date
}
}
});
}

resolve({
detected: detected,
version: versionString,
isEvergreenBootstrap: evergreen,
eocp: eocp, // <-- If true, it has already been removed
eom: eom
});
});
},

detectUI5VersionInFileV2: async function (fileContentText, repo) {
var that = this;
// console.log(fileContentText);
Expand Down Expand Up @@ -201,12 +129,9 @@ var SRBGitHub = (function () {
eocp = eocp;

Check failure on line 129 in UI5_Quality_Checks_App/webapp/libs/SRBGitHub.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

'eocp' is assigned to itself
eom = eom;

Check failure on line 130 in UI5_Quality_Checks_App/webapp/libs/SRBGitHub.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

'eom' is assigned to itself
} else {
var checks = that.checkForPatchSupport(patches, versionString);
if (checks) {
var { eocp, eom } = checks;
eocp = eocp;
eom = eom;
}
var { eocp, eom } = that.checkForPatchSupport(patches, versionString);

Check failure on line 132 in UI5_Quality_Checks_App/webapp/libs/SRBGitHub.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

'eocp' is already defined

Check failure on line 132 in UI5_Quality_Checks_App/webapp/libs/SRBGitHub.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

'eom' is already defined
eocp = eocp;

Check failure on line 133 in UI5_Quality_Checks_App/webapp/libs/SRBGitHub.js

View workflow job for this annotation

GitHub Actions / srb-reuse-linter / js-linter-job

'eocp' is assigned to itself
eom = eom;
}
}
}
Expand Down Expand Up @@ -235,13 +160,14 @@ var SRBGitHub = (function () {

checkForPatchSupport: function (patches, currentVersion) {
if (!patches) patches = availableVersionsModel.getData().patches;
var returnValues;
var returnValues = undefined;
patches.forEach((patch) => {
if (patch.version === currentVersion) {
if (patch.removed === true) returnValues = { eocp: "Reached", eom: "Reached" };
else returnValues = { eocp: patch.eocp, eom: "" };
else returnValues = { eocp: patch.eocp, eom: "No Information found" };
}
});
if (returnValues === undefined) returnValues = { eocp: true, eom: true };
return returnValues;
},

Expand Down
Loading

0 comments on commit 171666a

Please sign in to comment.