admin-shell.html 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <dom-module id="admin-shell">
  2. <style is="custom-style" include="iron-flex iron-positioning"></style>
  3. <style>
  4. app-header {
  5. background-color: var(--zebra-dark-gray);
  6. }
  7. app-toolbar {
  8. color: white;
  9. }
  10. .header {
  11. height: 64px;
  12. background-color: var(--zebra-dark-gray);
  13. }
  14. .separator {
  15. font-size: 14px;
  16. font-weight: 500;
  17. color: #aaa;
  18. border-top: 1px solid #e0e0e0;
  19. }
  20. .admin-header {
  21. height: 64px;
  22. background-color: #ebebeb;
  23. }
  24. iron-pages {
  25. height: 100%;
  26. }
  27. .default-content {
  28. margin: 8px;
  29. padding: 8px;
  30. background-color: white;
  31. }
  32. .login-container {
  33. margin: 0;
  34. width: 100%;
  35. height: 100%;
  36. }
  37. </style>
  38. <template>
  39. <template is="dom-if" if="{{adminExists()}}" restamp="true">
  40. <app-drawer-layout fullbleed>
  41. <app-drawer>
  42. <div class="header"></div>
  43. <div class="admin-header"></div>
  44. <paper-menu selected="{{selected}}" attr-for-selected="item">
  45. <paper-item class="first-item" item="home">Home</paper-item>
  46. <paper-item class="separator" disabled="true">Markdown</paper-item>
  47. <paper-item item="markdown-editor-add">Add Item</paper-item>
  48. <paper-item item="markdown-editor-update">Update Item</paper-item>
  49. <paper-item item="markdown-editor-delete">Delete Item</paper-item>
  50. <paper-item class="separator" disabled="true">Tool Operations</paper-item>
  51. <paper-item item="add-tool">Add Tool</paper-item>
  52. <paper-item item="update-tool">Update Tool</paper-item>
  53. <paper-item item="remove-tool">Remove Tool</paper-item>
  54. </paper-menu>
  55. </app-drawer>
  56. <app-header-layout fullbleed>
  57. <app-header>
  58. <app-toolbar>
  59. <paper-icon-button icon="menu" drawer-toggle></paper-icon-button>
  60. <div main-title>Admin Console</div>
  61. </app-toolbar>
  62. </app-header>
  63. <iron-pages selected="{{selected}}" attr-for-selected="item">
  64. <paper-material class="default-content" item="home">
  65. TEST
  66. </paper-material>
  67. <!-- Markdown Subsection -->
  68. <admin-markdown-add item="markdown-editor-add"></admin-markdown-add>
  69. <paper-material class="default-content" item="markdown-editor-update">
  70. Update Item
  71. </paper-material>
  72. <admin-markdown-delete item="markdown-editor-delete"></admin-markdown-delete>
  73. <!-- Tool Subsection -->
  74. <admin-add-tool-form item="add-tool"></admin-add-tool-form>
  75. <paper-material class="default-content" item="update-tool">
  76. Update Tool
  77. </paper-material>
  78. <admin-remove-tool-form item="remove-tool"></admin-remove-tool-form>
  79. </iron-pages>
  80. </app-header-layout>
  81. </app-drawer-layout>
  82. </template>
  83. <div class="login-container">
  84. <template is="dom-if" if="{{!adminExists()}}">
  85. <admin-login id="login" on-admin-login-success="_handleLogin" opened></admin-login>
  86. </template>
  87. </div>
  88. </template>
  89. <script>
  90. Polymer({
  91. is: 'admin-shell',
  92. properties: {
  93. /**
  94. * The logged in state of the user
  95. */
  96. loggedIn: {
  97. type: Boolean,
  98. value: false
  99. },
  100. /**
  101. * The currently selected item
  102. */
  103. selected: {
  104. type: Number,
  105. value: 0
  106. },
  107. },
  108. attached: function () {
  109. },
  110. /**
  111. * Helper function for checking if an admin exists (i.e. is a token in sessionStorage)
  112. * @returns {boolean} Whether or not an admin is logged in
  113. */
  114. adminExists: function () {
  115. var adminExists = false;
  116. //Check token
  117. if (sessionStorage.token) {
  118. adminExists = true;
  119. }
  120. return adminExists;
  121. },
  122. /**
  123. * Helper function for handling the login from admin-login
  124. * @param e The event that admin-login fires
  125. * @param detail The details from the event
  126. * @private
  127. */
  128. _handleLogin: function (e, detail) {
  129. token = detail.token;
  130. sessionStorage.setItem('token', token);
  131. location.reload(true);
  132. }
  133. });
  134. </script>
  135. </dom-module>