diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/firebaseFirestore.js | 43 | ||||
-rw-r--r-- | src/components/mao-admin.js | 57 |
2 files changed, 96 insertions, 4 deletions
diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js index 10e285a..c43a77f 100644 --- a/src/actions/firebaseFirestore.js +++ b/src/actions/firebaseFirestore.js @@ -228,3 +228,46 @@ export const createComment = (postId, content) => (dispatch, getState) => { } } +//TODO: Make it per year, not hard coded... + +export const archiveClass2019 = () => (dispatch, getState) => { + if(getState().app.offline) { + alert('Failed to archive class. Please establish internet connection.'); + } else { + var docRef = firestore.collection('users'); + docRef.get().then((oldUsers) => { + oldUsers.forEach((user) => { + var newPath = firestore.collection('archived').doc('2019').collection('users'); + newPath.doc(user.id).set(user.data()); + + if(user.data().username && user.data().username.includes('2019')) { + console.log(user.data().username, user.id); + docRef.doc(user.id).delete(); + } + + docRef.doc(user.id).update({hours: 0}); + + }); + }); + } +} + +export const archiveCompetitions2019 = () => (dispatch, getState) => { + if(getState().app.offline) { + alert('Failed to archive competitions. Please establish internet connection.'); + } else { + var docRef = firestore.collection('competitions'); + docRef.get().then((oldCompetitions) => { + oldCompetitions.forEach((comp) => { + console.log(comp.id, comp.data()); + var newPath = firestore.collection('archived').doc('2019').collection('competitions'); + newPath.doc(comp.id).set(comp.data()); + + //This will delete the document in its old place... + docRef.doc(comp.id).delete(); + + }); + }); + + } +} diff --git a/src/components/mao-admin.js b/src/components/mao-admin.js index 05357fc..19bf16e 100644 --- a/src/components/mao-admin.js +++ b/src/components/mao-admin.js @@ -17,7 +17,10 @@ import { store } from '../store.js'; // These are the shared styles needed by this element. import { SharedStyles } from './shared-styles.js'; -import { ButtonSharedStyles } from './button-shared-styles.js' +import { ButtonSharedStyles } from './button-shared-styles.js'; + +//These are the actions needed by this element. +import { archiveClass2019, archiveCompetitions2019 } from '../actions/firebaseFirestore.js'; // Import paper elements import '@polymer/paper-input/paper-input.js'; @@ -56,10 +59,36 @@ class MaoAdmin extends connect(store)(PageViewElement) { text-align: center; } + .white { + background-color: white; + + width: 50%; + + display: block; + margin-right: auto; + margin-left: auto; + } + + .search-grid { + display: grid; + + grid-template-columns: 1fr; + } + + .search-grid > paper-button { + display: grid; + + background-color: white; + } + @media (min-width: 460px) { .main-grid { grid-template-columns: 1fr 1fr 1fr; } + + .search-grid { + grid-template-columns: 3fr 1fr; + } } </style> @@ -72,7 +101,7 @@ class MaoAdmin extends connect(store)(PageViewElement) { <div class="main-grid"> <paper-button raised class="info" id="toggleRequestsBtn" on-tap="${() => this.toggleRequests()}">Show Hours Requests</paper-button> - <paper-button raised class="info" id="toggleRegistryBtn" on-tap="${() => this.toggleRegistry()}">Show Competitions And Registry</paper-button> + <paper-button raised class="info" id="toggleRegistryBtn" on-tap="${() => this.toggleRegistry()}">Show Comps & Registry</paper-button> <paper-button raised class="info" id="toggleRegistryBtn" on-tap="${() => this.usersHidden = !this.usersHidden}">${props.usersHidden ? 'Show User Data' : 'Hide User Data'}</paper-button> </div> @@ -89,6 +118,8 @@ class MaoAdmin extends connect(store)(PageViewElement) { </div> <div hidden="${props.registryHidden}"> + <paper-button on-tap="${() => this.confirmArchiveComps()}" class="white" raised>Archive Current Competitions</paper-button> + <br/> <div id="registry-grid" class="main-grid"></div> </div> @@ -101,8 +132,14 @@ class MaoAdmin extends connect(store)(PageViewElement) { </div> <section hidden="${!props.isAdmin || props.usersHidden}"> - <label>Search feature</label> - <paper-input id="search" oninput="${() => this.search()}" label="Search for keyword (ex. theta, mfoiani, 2019, ...ect)"></paper-input> + + <div class="search-grid"> + + <paper-input id="search" oninput="${() => this.search()}" label="Search for keyword (ex. theta, mfoiani, 2019, ...ect)"></paper-input> + + <paper-button raised on-tap="${() => this.confirmArchiveUsers()}">Archive Old Class</paper-button> + + </div> <br/> @@ -204,6 +241,18 @@ class MaoAdmin extends connect(store)(PageViewElement) { }); } + confirmArchiveUsers() { + if(confirm('This will archive current hours and set all accounts with zero hours. It will also hide those in the previous graduating class. Are you sure that you want to do this?')){ + store.dispatch(archiveClass2019()); + } + } + + confirmArchiveComps() { + if(confirm('This will archive all current competitions and remove the registry for them. Are you sure that you want to do this?')) { + store.dispatch(archiveCompetitions2019()); + } + } + updateInformation() { if(this.shadowRoot) { //update requests |