Skip to content

Commit

Permalink
Feature/optimize for golive (#6)
Browse files Browse the repository at this point in the history
* Added status to reset function
* Switching to one-pager
* Changed SWA config
* Added confirm dialog for delete
  • Loading branch information
aessing authored Apr 23, 2021
1 parent 280dd47 commit b01b38e
Show file tree
Hide file tree
Showing 23 changed files with 13,869 additions and 5,930 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 120,
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"jsxBracketSameLine": true
Expand Down
6 changes: 4 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"ms-azuretools.vscode-azurefunctions",
"ms-azuretools.vscode-azurestaticwebapps",
"ms-azuretools.vscode-azurestorage",
"ritwickdey.liveserver",
"esbenp.prettier-vscode"
"ms-azuretools.vscode-logicapps",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ritwickdey.liveserver"
]
}
File renamed without changes.
45 changes: 45 additions & 0 deletions api/GetClasses/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const tableStore = require(`azure-storage`);

module.exports = async function (context, req) {
context.res = {
status: 200,
body: await getTestStatus(),
headers: {
'Content-Type': 'application/json',
'X-Content-Type-Options': 'nosniff',
},
};
};

async function getTestStatus() {
const tableService = tableStore.createTableService();
const statusQuery = new tableStore.TableQuery().select([
`PartitionKey`,
`Status`,
]);

return new Promise(function (resolve, reject) {
tableService.queryEntities(
process.env['STATUSTABLE_NAME'],
statusQuery,
null,
function (error, result) {
if (!error) {
let entities = result.entries;
let resultSet = new Array();

entities.forEach(function (entity) {
resultSet.push({
class: entity.PartitionKey._,
status: entity.Status._,
});
});

resolve(JSON.stringify(resultSet));
} else {
reject(error.message);
}
}
);
});
}
37 changes: 0 additions & 37 deletions api/GetTestStatus/index.js

This file was deleted.

16 changes: 10 additions & 6 deletions api/RemoveClass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ async function removeClass(testClass) {
};

return new Promise(function (resolve, reject) {
tableService.deleteEntity(process.env['STATUSTABLE_NAME'], updatedStatus, function (error) {
if (!error) {
resolve(200);
} else {
reject(500);
tableService.deleteEntity(
process.env['STATUSTABLE_NAME'],
updatedStatus,
function (error) {
if (!error) {
resolve(200);
} else {
reject(500);
}
}
});
);
});
}
File renamed without changes.
55 changes: 35 additions & 20 deletions api/resetTestStatus/index.js → api/ResetClasses/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const tableStore = require(`azure-storage`);

module.exports = async function (context, req) {
const authKey = req.query.authkey || (req.body && req.body.authkey);
const paramAuthKey = req.query.authkey || (req.body && req.body.authkey);
const paramClassStatus = req.query.status || (req.body && req.body.status);

let classStatus = Number(paramClassStatus) === 3 ? paramClassStatus : 0;

let responseStatus;

if (process.env['RESET_AUTH_KEY'] === authKey) {
if (process.env['RESET_AUTH_KEY'] === paramAuthKey) {
let classes = await getClasses();
responseStatus = await resetTestStatus(classes);
responseStatus = await resetTestStatus(classes, classStatus);
} else {
responseStatus = 401;
}
Expand Down Expand Up @@ -42,22 +46,27 @@ async function getClasses() {
const statusQuery = new tableStore.TableQuery().select(`PartitionKey`);

return new Promise(function (resolve) {
tableService.queryEntities(process.env['STATUSTABLE_NAME'], statusQuery, null, function (error, result) {
if (!error) {
let entities = result.entries;
let resultSet = new Array();
tableService.queryEntities(
process.env['STATUSTABLE_NAME'],
statusQuery,
null,
function (error, result) {
if (!error) {
let entities = result.entries;
let resultSet = new Array();

entities.forEach(function (entity) {
resultSet.push(entity.PartitionKey._);
});
entities.forEach(function (entity) {
resultSet.push(entity.PartitionKey._);
});

resolve(resultSet);
resolve(resultSet);
}
}
});
);
});
}

async function resetTestStatus(classList) {
async function resetTestStatus(classList, classStatus) {
const tableService = tableStore.createTableService();

return new Promise(function (resolve, reject) {
Expand All @@ -70,17 +79,23 @@ async function resetTestStatus(classList) {
_: '',
},
Status: {
_: 0,
_: Number(classStatus),
},
};

tableService.replaceEntity(process.env['STATUSTABLE_NAME'], updatedStatus, function (error) {
if (!error) {
resolve(200);
} else {
reject(500);
console.log(updatedStatus);

tableService.replaceEntity(
process.env['STATUSTABLE_NAME'],
updatedStatus,
function (error) {
if (!error) {
resolve(200);
} else {
reject(500);
}
}
});
);
});
});
}
File renamed without changes.
16 changes: 10 additions & 6 deletions api/SetTestStatus/index.js → api/SetClassStatus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ async function setTestStatus(testClass, testStatus) {
};

return new Promise(function (resolve, reject) {
tableService.insertOrReplaceEntity(process.env['STATUSTABLE_NAME'], updatedStatus, function (error) {
if (!error) {
resolve(200);
} else {
reject(500);
tableService.insertOrReplaceEntity(
process.env['STATUSTABLE_NAME'],
updatedStatus,
function (error) {
if (!error) {
resolve(200);
} else {
reject(500);
}
}
});
);
});
}
159 changes: 0 additions & 159 deletions web/admin/index.html

This file was deleted.

Loading

0 comments on commit b01b38e

Please sign in to comment.