DONE: centralize theme color, interactive dashboard, increase winner result, refer TODO

This commit is contained in:
ISMAIL MASSERAN
2026-05-10 11:51:19 +08:00
parent 654a0c9fea
commit fd1baf34c8
47 changed files with 2680 additions and 932 deletions
+38 -20
View File
@@ -17,6 +17,23 @@ const methods = {
return localStorage['Access Token'] ? true : false;
},
/**
* True when the browser session is for the admin portal (not a voter-only token).
*/
isAdminPortalSession: function () {
return localStorage.getItem('admin_role') != null || localStorage.getItem('admin_session') === '1';
},
/**
* Route name to open for the current admin session (role 3 is restricted to kehadiran).
*/
getAdminEntryRoute: function () {
if (localStorage.getItem('admin_role') === '3') {
return { name: 'Kehadiran Calon' };
}
return { name: 'Admin Home' };
},
/**
* Log a messages
* @param {String} Message
@@ -60,7 +77,7 @@ const methods = {
<div class="progress-bar progress-bar-green" role="progressbar" aria-valuenow="${progress}" aria-valuemin="0" aria-valuemax="100" style="width: ${progress}%">
</div>
</div>`;
icon = 'fa fa-refresh fa-spin';
icon = 'fa fa-refresh fa-spin';
break;
}
@@ -70,7 +87,7 @@ const methods = {
}, {
type: type,
delay: delay,
placement: {from: 'top', align: 'center'}
placement: { from: 'top', align: 'center' }
});
},
@@ -81,7 +98,7 @@ const methods = {
*/
setAuthorization: function () {
axios.defaults.headers.common['Authorization'] = localStorage['Access Token'];
$.ajaxSetup({headers:{'Authorization': localStorage['Access Token']}});
$.ajaxSetup({ headers: { 'Authorization': localStorage['Access Token'] } });
},
@@ -100,14 +117,13 @@ const methods = {
* @param {Int} Response Status
* @return {String} Error Message
*/
getErrorMessage: function (data, status)
{
getErrorMessage: function (data, status) {
var message = '';
switch (status) {
case 200:
message = data.message;
break;
case 422:
case 422:
// Laravel validation errors are usually:
// { message: "...", errors: { field: ["..."] } }
// but some endpoints may return { status, message }.
@@ -148,10 +164,10 @@ const methods = {
}
break;
case 401:
message = 'You need to login first.';
message = 'Sila log masuk terlebih dahulu.';
break;
default:
message = 'An error occured.';
message = 'Ralat telah berlaku.';
break;
}
return message;
@@ -173,8 +189,8 @@ const methods = {
* @param {library} Library used (ajax|axios) Default : axios
*/
showResult: function (response, type, library = 'axios') {
this.log (response);
var isSuccess = data => data.status == 'success';
this.log(response);
var isSuccess = data => data.status == 'success';
if (library == 'axios') {
if (type == 'success') {
if (isSuccess(response.data)) {
@@ -184,11 +200,11 @@ const methods = {
this.notify(response.data.message, 'error');
}
} else {
var status = response.response ? response.response.status : 500;
var status = response.response ? response.response.status : 500;
var message = this.getErrorMessage(response.response.data, status);
this.notify(message, 'error');
return status;
}
}
} else if (library == 'ajax') {
if (type == 'success') {
if (isSuccess(response)) {
@@ -198,7 +214,7 @@ const methods = {
this.notify(response.message, 'error');
}
} else if (type == 'error') {
var status = response.status;
var status = response.status;
var message = this.getErrorMessage(response.responseText, status);
this.notify(message, 'error');
return status;
@@ -217,12 +233,12 @@ const data = {
positions: [],
position: {},
partylists: [],
partylist:{},
voters:{},
voter:{},
nominees:[],
nominee:{},
admins:[],
partylist: {},
voters: {},
voter: {},
nominees: [],
nominee: {},
admins: [],
information: {},
result: [],
results: [],
@@ -236,4 +252,6 @@ export default {
data: data
}
}
}
}
export { methods };