aboutsummaryrefslogtreecommitdiff
path: root/src/components/mao-admin.js
blob: a8e7435681270df52245082bc8867154d2ba1ef1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/**
@license
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

import { html } from '@polymer/lit-element';
import { PageViewElement } from './page-view-element.js';
import { connect } from 'pwa-helpers/connect-mixin.js';

// This element is connected to the Redux store.
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 paper elements
import '@polymer/paper-input/paper-input.js';
import '@polymer/paper-card/paper-card.js';
import '@polymer/paper-slider/paper-slider.js';
import '@polymer/paper-button/paper-button.js';

// Import custom elements
import './request-element.js';
import './registry-element.js';

class MaoAdmin extends connect(store)(PageViewElement) {
  _render(props) {
    return html`
      ${SharedStyles}
      ${ButtonSharedStyles}

      <style>

      paper-card {
        display: block;
      }

      paper-button {
        display:  block;
      }

      .main-grid {
        display:  grid;
        grid-gap: 10px;

        grid-template-columns: 1fr;
      }

      td {
        text-align: center;
      }

      @media (min-width: 460px) {
        .main-grid {
          grid-template-columns: 1fr 1fr 1fr;
        }
      }

      </style>



      <section hidden="${!props.isAdmin}">

        <h2 class="underline">Hello Admin!</h2>

        <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="${() => props.usersHidden = !props.usersHidden}">${props.usersHidden ? 'Show User Data' : 'Hide User Data'}</paper-button>
        </div>

        <br/>

        <div hidden="${props.requestsHidden}">
          <div id="requests-grid" class="main-grid"></div>
        </div>

        <div hidden="${props.registryHidden || props.requestsHidden}">
          <br/>
          <hr/>
          <br/>
        </div>

        <div hidden="${props.registryHidden}">
          <div id="registry-grid" class="main-grid"></div>
        </div>

      </section>

      <div hidden="${props.usersHidden}">
        <br/>
        <hr/>
        <br/>
      </div>

      <section hidden="${!props.isAdmin || props.usersHidden}">
        <table style="width: 100%;">
          <thead>
            <tr>
              <th>Username</th>
              <th>Hours</th> 
              <th>Divison</th>
            </tr>
          <thead>
          <tbody id="users-table-body">
          </tbody>
        </table>
      </section>
    `;
  }

  constructor() {
    super();

    this.requestsHidden = true;
    this.registryHidden = true;
    this.usersHidden    = true;
  }

  static get properties() { return {
    // This is the data from the store.
    signedIn:  Boolean,
    isAdmin:   Boolean,
    requests:  Array,
    registry:  Array,
    adminImgs: String,
    users:     Array,

    requestsHidden: Boolean,
    registryHidden: Boolean,
    usersHidden:    Boolean
  }}

  _firstRendered() {
    this.updateInformation();
  }
  
  _stateChanged(state) {
    this.signedIn = state.firebaseAuth  .signedIn;
    this.isAdmin  = state.firebaseAdmin .isAdmin;
    this.requests = state.firebaseAdmin .requests;
    this.registry = state.firebaseAdmin .compList;
    this.users    = state.firebaseAdmin .userList;
    this.adminImgs = state.firebaseAdmin.adminImgs;

    this.updateInformation();
  }

  toggleRequests() {
    this.requestsHidden = !this.requestsHidden;

    if(this.shadowRoot) {
      var btn = this.shadowRoot.getElementById('toggleRequestsBtn');
      if(this.requestsHidden) {
        btn.innerHTML = "Show Hours Requests";
      } else {
        btn.innerHTML = "Hide Hours Requests";
      }
    } else {
      console.log("Null shadow root");
    }
  }

  toggleRegistry() {
    this.registryHidden = !this.registryHidden;

    if(this.shadowRoot) {
      var btn = this.shadowRoot.getElementById('toggleRegistryBtn');
      if(this.registryHidden) {
        btn.innerHTML = "Show Comps & Registry";

      } else {
        btn.innerHTML = "Hide Comps & Registry";
      }
    } else {
      console.log("Null shadow root");
    }
  }

  updateInformation() {
    if(this.shadowRoot) {
      //update requests
      var requestGrid       = this.shadowRoot.getElementById('requests-grid');
      requestGrid.innerHTML = "";

      for(var i = 0; i<this.requests.length; i++) {
        var requestElement  = document.createElement('request-element');

        requestElement.email    = this.requests[i].email
                                .replace('@communityschoolnaples.org', '');
        requestElement.date     = this.requests[i].day;
        requestElement.location = this.requests[i].location;
        requestElement.time     = this.requests[i].time;
        requestElement.trainee  = this.requests[i].trainee;
        requestElement.subject  = this.requests[i].subject;
        requestElement.uid      = this.requests[i].uid;
        requestElement.docId    = this.requests[i].docId;
        requestElement.imgUrl   = this.requests[i].imgUrl;
        requestElement.imgPath  = this.requests[i].path;

        requestGrid.appendChild(requestElement);
      }

      //update registry
      var registryGrid        = this.shadowRoot.getElementById('registry-grid');
      registryGrid.innerHTML  = "";

      for(var i = 0; i<this.registry.length; i++) {
        var registryElement   = document.createElement('registry-element');

        registryElement.name      = this.registry[i].name;
        registryElement.emails    = this.registry[i].emails;
        registryElement.divisons  = this.registry[i].divisons;

        registryGrid.appendChild(registryElement);
      }

      //update users
      var tableBody         = this.shadowRoot.getElementById('users-table-body');
      tableBody.innerHTML   = "";

      this.users.forEach((user) => {
        user = user.data();

        var tableRow = document.createElement('tr');

        var userEle = document.createElement('td');
        userEle.innerHTML = user['username'] ? user['username'] : "Unknown";


        var hoursEle        = document.createElement('td');
        hoursEle.innerHTML  = user['hours'];

        if(user['hours'] <= 1.0) {
          hoursEle.style.color = 'red';
        }

        else if (user['hours'] < 5.0) {
          hoursEle.style.color = '#f09300';
        }

        else {
          hoursEle.style.color = 'green';
        }


        var divisonEle = document .createElement('td');
        divisonEle.innerHTML  = user['divison'];
        switch (user['divison']) {
          case 'Mu':
            divisonEle.style.color = "#f09300";
          break;
          
          case 'Alpha':
            divisonEle.style.color = "#7baaf7";
          break;

          case 'Theta':
            divisonEle.style.color = "green";
          break;

          case 'Stats':
            divisonEle.style.color = "red";
          break;

          default:
            divisonEle.style.color = "black";
        }
      
        
        tableRow  .appendChild(userEle);
        tableRow  .appendChild(hoursEle);
        tableRow  .appendChild(divisonEle);
        tableBody .appendChild(tableRow);
      });
    }
  }


}

window.customElements.define('mao-admin', MaoAdmin);