Skip to content

Commit

Permalink
Working changes for school screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Sep 15, 2022
1 parent 60f5c90 commit 59a7329
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 59 deletions.
4 changes: 2 additions & 2 deletions backend/src/components/cache-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const cacheService = {
await retry(async () => {
// if anything throws, we retry
const data = await getApiCredentials(); // get the tokens first to make api calls.
const schoolsResponse = await getData(data.accessToken, `${config.get('instituteAPIURL')}/school`);
const schoolsResponse = await getData(data.accessToken, `${config.get('institute:rootURL')}/school`);
schools = []; // reset the value.
schoolMap.clear();// reset the value.
mincode_school_ID_Map.clear();
Expand Down Expand Up @@ -83,7 +83,7 @@ const cacheService = {
log.debug('loading all districtsMap during start up');
await retry(async () => {
const data = await getApiCredentials();
const districtsResponse = await getData(data.accessToken, `${config.get('instituteAPIURL')}/district`);
const districtsResponse = await getData(data.accessToken, `${config.get('institute:rootURL')}/district`);
// reset the value.
districts = [];
activeDistricts = [];
Expand Down
2 changes: 2 additions & 0 deletions backend/src/components/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ cacheKeys = {
EDX_SECURE_EXCHANGE_STATUS: 'edx_exchangeStatuses',
EDX_MINISTRY_TEAMS:'edx_ministryTeams',
EDX_ROLE_PERMISSIONS:'edx_rolePermissions',
SCHOOL_FACILITY_TYPES:'school_facilityTypes',
SCHOOL_CATEGORY_TYPES:'school_categoryTypes',
EDX_SECURE_EXCHANGE_DOCUMENT_TYPES: 'edx_secureExchangeDocumentTypes',
EDX_SECURE_EXChANGE_FILE_REQUIREMENTS: 'edx_secureExchangeFileRequirements'
};
Expand Down
2 changes: 1 addition & 1 deletion backend/src/components/district.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function getDistrictByDistrictID(req, res){
checkEDXUserAccess(req, res, 'DISTRICT', req.params.districtID);

return Promise.all([
getData(token, `${config.get('instituteAPIURL')}/district/${req.params.districtID}`, req.session?.correlationID),
getData(token, `${config.get('institute:rootURL')}/district/${req.params.districtID}`, req.session?.correlationID),
])
.then(async ([dataResponse]) => {
return res.status(200).json(dataResponse);
Expand Down
6 changes: 3 additions & 3 deletions backend/src/components/school.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function getSchoolBySchoolID(req, res) {
}
}

async function getAllCachedSchools(req, res){
async function getAllCachedSchools(_req, res){
try {
let allActiveSchools = cacheService.getAllActiveSchoolsJSON();
return res.status(200).json(allActiveSchools ? allActiveSchools : []);
Expand All @@ -38,7 +38,7 @@ async function getFullSchoolDetails(req, res){
validateAccessToken(token);

return Promise.all([
getData(token, `${config.get('instituteAPIURL')}/school/${req.params.schoolID}`, req.session?.correlationID),
getData(token, `${config.get('institute:rootURL')}/school/${req.params.schoolID}`, req.session?.correlationID),
])
.then(async ([dataResponse]) => {
return res.status(200).json(dataResponse);
Expand Down Expand Up @@ -91,7 +91,7 @@ async function getSchoolsPaginated(req, res){
}
};

return getDataWithParams(accessToken, config.get('instituteAPIURL') + '/school/paginated', schoolSearchParam, req.session?.correlationID);
return getDataWithParams(accessToken, config.get('institute:rootURL') + '/school/paginated', schoolSearchParam, req.session?.correlationID);
}

function createSchoolSearchCriteria(searchParams){
Expand Down
4 changes: 3 additions & 1 deletion backend/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ nconf.defaults({
schoolUserActivationInviteURL:process.env.EDX_API_ENDPOINT+ '/exchange'+'/school-user-activation-invite-saga',
activationCodeUrl: process.env.EDX_API_ENDPOINT + '/users/activation-code'
},
instituteAPIURL: process.env.INSTITUTE_API_ENDPOINT,
institute:{
rootURL: process.env.INSTITUTE_API_ENDPOINT
}
});
module.exports = nconf;
4 changes: 4 additions & 0 deletions backend/src/routes/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const express = require('express');
const router = express.Router();
const { getSchoolBySchoolID, getAllCachedSchools, getAllSchoolDetails, getFullSchoolDetails } = require('../components/school');
const auth = require('../components/auth');
const {getCodes} = require('../components/utils');
const {CACHE_KEYS} = require('../components/constants');
const isValidBackendToken = auth.isValidBackendToken();

/*
Expand All @@ -13,6 +15,8 @@ router.get('/lastUpdated', passport.authenticate('jwt', {session: false}, undefi
router.get('/allCachedSchools', passport.authenticate('jwt', {session: false}, undefined), isValidBackendToken, getAllCachedSchools);
router.get('/allSchools', passport.authenticate('jwt', {session: false}, undefined), isValidBackendToken, getAllSchoolDetails);
router.get('/schoolDetailsById/:schoolID', passport.authenticate('jwt', {session: false}, undefined), isValidBackendToken, getFullSchoolDetails);
router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), isValidBackendToken, getCodes('institute:rootURL', CACHE_KEYS.SCHOOL_FACILITY_TYPES, '/facility-codes'));
router.get('/school-category-types', passport.authenticate('jwt', {session: false}, undefined), isValidBackendToken, getCodes('institute:rootURL', CACHE_KEYS.SCHOOL_CATEGORY_TYPES, '/category-codes'));

module.exports = router;

19 changes: 19 additions & 0 deletions frontend/src/common/apiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ export default {
}
},

async getFacilityTypeCodes() {
try{
return await apiAxios.get(ApiRoutes.school.FACILITY_TYPES_URL);
} catch(e) {
console.log(`Failed to get from Nodejs getFacilityTypeCodes API - ${e}`);
throw e;
}
},

async getSchoolCategoryTypeCodes() {
try{
return await apiAxios.get(ApiRoutes.school.SCHOOL_CATEGORY_TYPES_URL);
} catch(e) {
console.log(`Failed to get from Nodejs getSchoolCategoryTypeCodes API - ${e}`);
throw e;
}
},


async getFileRequirements() {
try{
return await apiAxios.get(ApiRoutes.edx.FILE_REQUIREMENTS_URL);
Expand Down
82 changes: 33 additions & 49 deletions frontend/src/components/school/SchoolList.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
<template>
<v-container class="containerSetup" fluid>
<v-row style="background: rgb(235, 237, 239);border-radius: 8px;" class="px-3">
<v-col cols="12" md="3" class="d-flex justify-start">
<v-select id="name-text-field" label="School Code & Name" item-value="mincode" item-text="schoolCodeName"
:items="schoolSearchNames" v-model="schoolCodeNameFilter" clearable></v-select>
<v-col cols="12" md="5" class="d-flex justify-start">
<v-autocomplete
id="name-text-field"
label="School Code & Name"
item-value="mincode"
item-text="schoolCodeName"
:items="schoolSearchNames"
v-model="schoolCodeNameFilter"
clearable>
<template v-slot:selection="{ item }">
<span> {{ item.schoolCodeName }} </span>
</template>
</v-autocomplete>
</v-col>
<v-col cols="12" md="2" class="d-flex justify-start">
<v-select id="status-select-field" clearable :items="schoolStatus" v-model="schoolStatusFilter" item-text="name"
item-value="code" label="Status"></v-select>
</v-col>
<v-col cols="12" md="2" class="d-flex justify-start">
<v-select id="status-select-field" clearable :items="schoolCategories" v-model="schoolCategoryFilter" item-text="name"
item-value="code" label="School Category"></v-select>
</v-col>
<v-col cols="12" md="3" class="d-flex justify-start">
<v-select id="status-select-field" clearable :items="schoolFacilityTypes" v-model="schoolFacilityTypeFilter" item-text="name"
item-value="code" label="Facility Type"></v-select>
<v-select
id="status-select-field"
clearable
:items="schoolFacilityTypes"
v-model="schoolFacilityTypeFilter"
item-text="label"
item-value="facilityTypeCode" label="Facility Type"></v-select>
</v-col>
<v-col cols="12" md="2" class="mt-6 d-flex justify-end">
<PrimaryButton id="user-search-button" text="Clear" secondary @click.native="clearButtonClick"/>
Expand Down Expand Up @@ -177,16 +188,17 @@ export default {
schools: [],
schoolSearchNames: [],
schoolStatus: [],
schoolCategories: [],
schoolFacilityTypes: [],
schoolCodeNameFilter: '',
schoolStatusFilter: '',
schoolCategoryFilter: '',
schoolFacilityTypes: [],
schoolCategoryTypes: [],
schoolFacilityTypeFilter: '',
};
},
computed: {
...mapState('app', ['schoolsMap']),
...mapState('institute', ['facilityTypeCodes']),
...mapState('institute', ['schoolCategoryTypeCodes']),
getSheetWidth(){
switch (this.$vuetify.breakpoint.name) {
Expand All @@ -201,25 +213,21 @@ export default {
created() {
this.$store.dispatch('edx/getMinistryTeams');
this.$store.dispatch('app/getInstitutesData');
this.$store.dispatch('institute/getFacilityTypeCodes').then(() => {
this.schoolFacilityTypes = this.facilityTypeCodes;
});
this.$store.dispatch('institute/getSchoolCategoryTypeCodes').then(() => {
this.schoolCategoryTypes = this.schoolCategoryTypeCodes;
});
this.setSchoolStatuses();
this.setSchoolCategories();
this.setSchoolFacilityTypes();
this.getSchoolDropDownItems();
this.getSchoolList();
},
methods: {
setSchoolStatuses() {
this.schoolStatus = [{name: 'Open', code: 'Open'}, {name: 'Opening', code: 'Opening'}, {name: 'Closing', code: 'Closing'}, {name: 'Closed', code: 'Closed'}];
},
setSchoolCategories() {
this.schoolCategories = [{name: 'Public School', code:'PUBLIC'},{name: 'Independent School', code:'INDEPEND'},
{name: 'Yukon School', code:'YUKON'},{name: 'Indigenous School', code:'FED_BAND'},{name: 'Offshore School', code:'OFFSHORE'}];
},
setSchoolFacilityTypes() {
this.schoolFacilityTypes = [{name: 'Standard School', code:'STANDARD'},{name: 'Offshore School', code:'OFFSHORE'},{name: 'Distance Learning', code:'DIST_LEARN'}];
},
getSchoolDropDownItems(){
ApiService.apiAxios.get(ApiRoutes.school.ALL_CACHE_SCHOOLS, {
params: {}
Expand All @@ -246,7 +254,6 @@ export default {
this.headerSearchParams.schoolNumber = this.schoolCodeNameFilter.substring(3);
}
this.headerSearchParams.status = this.schoolStatusFilter;
this.headerSearchParams.category = this.schoolCategoryFilter;
this.headerSearchParams.type = this.schoolFacilityTypeFilter;
ApiService.apiAxios.get(ApiRoutes.school.ALL_DIS_SCHOOLS, {
Expand Down Expand Up @@ -281,30 +288,10 @@ export default {
},
getFacilityType(school){
let type = null;
if(school.facilityTypeCode === 'STANDARD'){
type = 'Standard School';
} else if(school.facilityTypeCode === 'OFFSHORE'){
type = 'Offshore School';
} else if(school.facilityTypeCode === 'DIST_LEARN'){
type = 'Distance Learning';
}
return type;
return this.schoolFacilityTypes.find((facility) => facility.facilityTypeCode === school.facilityTypeCode).label;
},
getSchoolCategory(school){
let category = null;
if(school.schoolCategoryCode === 'PUBLIC'){
category = 'Public School';
} else if(school.schoolCategoryCode === 'INDEPEND'){
category = 'Independent School';
} else if(school.schoolCategoryCode === 'YUKON'){
category = 'Yukon School';
} else if(school.schoolCategoryCode === 'FED_BAND'){
category = 'Indigenous School';
} else if(school.schoolCategoryCode === 'OFFSHORE'){
category = 'Offshore School';
}
return category;
return this.schoolCategoryTypeCodes.find((category) => category.schoolCategoryCode === school.schoolCategoryCode).label;
},
getPrincipalsName(contacts) {
let principalsName = null;
Expand Down Expand Up @@ -345,25 +332,22 @@ export default {
}
},
openSchool(schoolId){
console.log('OPEN_SCHOOL_ID:= ' + schoolId);
this.$router.push({name: 'viewSchool', params: {schoolID: schoolId}});
},
resetPageNumber(){
this.pageNumber = 1;
},
searchEnabled(){
return (this.schoolCodeNameFilter !== '' && this.schoolCodeNameFilter !== null) || (this.schoolStatusFilter !== '' && this.schoolStatusFilter !== null)
|| (this.schoolCategoryFilter !== '' & this.schoolCategoryFilter !== null) || this.schoolFacilityTypeFilter !== '' && this.schoolFacilityTypeFilter !== null;
|| this.schoolFacilityTypeFilter !== '' && this.schoolFacilityTypeFilter !== null;
},
clearButtonClick() {
this.schoolCodeNameFilter = '';
this.schoolStatusFilter = '';
this.schoolCategoryFilter = '';
this.schoolFacilityTypeFilter = '';
this.headerSearchParams.schoolNumber = '';
this.headerSearchParams.status = '';
this.headerSearchParams.category = '';
this.headerSearchParams.type = '';
this.getSchoolList();
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import Vuex from 'vuex';
import auth from '@/store/modules/auth.js';
import edx from '@/store/modules/edx.js';
import app from '@/store/modules/app.js';
import institute from '@/store/modules/institute.js';
Vue.use(Vuex);

export default new Vuex.Store({
modules: {
auth,
edx,
app
app,
institute
}
});
31 changes: 31 additions & 0 deletions frontend/src/store/modules/institute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ApiService from '@/common/apiService';

export default {
namespaced: true,
state: {
facilityTypeCodes: null,
schoolCategoryTypeCodes: null
},
getters: {
facilityTypeCodes: state => state.facilityTypeCodes,
schoolCategoryTypeCodes: state => state.schoolCategoryTypeCodes
},
mutations: {
setFacilityTypeCodes: (state, facilityTypeCodes) => {
state.facilityTypeCodes = facilityTypeCodes;
},
setSchoolCategoryTypeCodes: (state, schoolCategoryTypeCodes) => {
state.schoolCategoryTypeCodes = schoolCategoryTypeCodes;
}
},
actions: {
async getFacilityTypeCodes({commit}) {
const response = await ApiService.getFacilityTypeCodes();
commit('setFacilityTypeCodes', response.data);
},
async getSchoolCategoryTypeCodes({commit}) {
const response = await ApiService.getSchoolCategoryTypeCodes();
commit('setSchoolCategoryTypeCodes', response.data);
}
}
};
2 changes: 2 additions & 0 deletions frontend/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const ApiRoutes = Object.freeze({
ALL_DIS_SCHOOLS: schoolRoot + '/allSchools',
ALL_CACHE_SCHOOLS: schoolRoot + '/allCachedSchools',
SCHOOL_DETAILS_BY_ID: schoolRoot + '/schoolDetailsById',
FACILITY_TYPES_URL: schoolRoot + '/facility-types',
SCHOOL_CATEGORY_TYPES_URL: schoolRoot + '/school-category-types',
},
district: {
BASE_URL: districtRoot
Expand Down
Loading

0 comments on commit 59a7329

Please sign in to comment.