App.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div id="app">
  3. <!-- loading screen -->
  4. <loading-overlay v-if="!connected"/>
  5. <!-- top navigation bar -->
  6. <top-navigation-bar :window="window"
  7. :current-project="currentProject"
  8. v-on:side="window.menu = !window.menu"></top-navigation-bar>
  9. <!-- bottom content -->
  10. <div class="bottom">
  11. <!-- side navigation bar -->
  12. <side-navigation-bar :window="window"
  13. :socket="socket"
  14. :status="status"
  15. :current-project="currentProject"
  16. v-on:close="window.menu = false"/>
  17. <!-- actual content -->
  18. <div class="content">
  19. <project-open-window v-if="window.content === 'projects'"
  20. :projects="projects"
  21. :status="status"
  22. :socket="socket"
  23. :window="window"
  24. v-on:open="openProject"/>
  25. <project-settings-window v-if="window.content === 'settings'"
  26. :current-project="currentProject"
  27. :status="status"
  28. :socket="socket"
  29. v-on:close="closeProject"/>
  30. <project-data-add-window v-if="window.content === 'add_data'"
  31. :current-project="currentProject"
  32. :socket="socket"/>
  33. <project-data-view-window v-if="window.content === 'view_data'"
  34. :current-project="currentProject"
  35. :status="status"
  36. :socket="socket"/>
  37. <about-window v-if="window.content === 'about'"/>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import io from "socket.io-client";
  44. import ProjectOpenWindow from "@/components/projects/project-open-window";
  45. import TopNavigationBar from "@/components/window/top-navigation-bar";
  46. import SideNavigationBar from "@/components/window/side-navigation-bar";
  47. import ProjectSettingsWindow from "@/components/projects/project-settings-window";
  48. import AboutWindow from "@/components/other/about-window";
  49. import ProjectDataAddWindow from "@/components/projects/project-data-add-window";
  50. import ProjectDataViewWindow from "@/components/projects/project-data-view-window";
  51. import LoadingOverlay from "@/components/other/loading-overlay";
  52. export default {
  53. name: 'App',
  54. components: {
  55. LoadingOverlay,
  56. ProjectDataAddWindow,
  57. ProjectDataViewWindow,
  58. AboutWindow,
  59. ProjectSettingsWindow,
  60. SideNavigationBar,
  61. TopNavigationBar,
  62. ProjectOpenWindow
  63. },
  64. data: function() {
  65. return {
  66. connected: false,
  67. socket: {
  68. baseurl: window.location.protocol + '//' + window.location.hostname + ':5000',
  69. // initialize socket.io connection
  70. io: io(window.location.protocol + '//' + window.location.hostname + ':5000'),
  71. // http methods
  72. post: function(name, value) {
  73. return fetch(this.baseurl + name, {
  74. method: 'POST',
  75. body: JSON.stringify(value)
  76. });
  77. },
  78. upload: function(name, file) {
  79. const form = new FormData();
  80. form.append('file', file);
  81. return fetch(this.baseurl + name, {
  82. method: 'POST',
  83. body: form
  84. });
  85. },
  86. media: function(projectId, fileId) {
  87. return this.baseurl + '/projects/' + projectId + '/data/' + fileId;
  88. }
  89. },
  90. status: null,
  91. window: {
  92. wide: true,
  93. menu: false,
  94. content: 'projects',
  95. project: null
  96. }
  97. }
  98. },
  99. computed: {
  100. projects: function() {
  101. if (this.status == null)
  102. return [];
  103. return Object.keys(this.status.projects).map(key => this.status.projects[key]);
  104. },
  105. currentProject: function() {
  106. for (let i = 0; i < this.projects.length; i++)
  107. if (this.projects[i].id === this.window.project)
  108. return this.projects[i];
  109. return false;
  110. }
  111. },
  112. methods: {
  113. resize: function() {
  114. this.window.wide = (document.body.offsetWidth > 1024);
  115. },
  116. show: function(value) {
  117. this.window.content = value;
  118. },
  119. openProject: function(project) {
  120. this.window.project = project.id;
  121. this.show('settings');
  122. },
  123. closeProject: function() {
  124. this.window.project = null;
  125. this.show('projects');
  126. }
  127. },
  128. created: function() {
  129. this.socket.io.on('app_status', status => {
  130. this.status = status;
  131. this.connected = true;
  132. });
  133. setInterval(() => this.connected = this.socket.io.connected, 2000);
  134. window.addEventListener('resize', this.resize);
  135. this.resize();
  136. },
  137. destroyed: function() {
  138. window.removeEventListener('resize', this.resize);
  139. }
  140. }
  141. </script>
  142. <style scoped>
  143. #app {
  144. width: 100%;
  145. height: 100%;
  146. display: flex;
  147. flex-direction: column;
  148. }
  149. .bottom {
  150. display: flex;
  151. flex-grow: 1;
  152. flex-direction: row;
  153. width: 100%;
  154. position: relative;
  155. }
  156. .content {
  157. flex-grow: 1;
  158. overflow: hidden;
  159. }
  160. .content > * {
  161. width: 100%;
  162. height: 100%;
  163. }
  164. </style>