App.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div id="app">
  3. <!-- top navigation bar -->
  4. <top-navigation-bar :window="window"
  5. :current-project="currentProject"
  6. v-on:side="window.menu = !window.menu"></top-navigation-bar>
  7. <!-- bottom content -->
  8. <div class="bottom">
  9. <!-- side navigation bar -->
  10. <side-navigation-bar :window="window"
  11. :socket="socket"
  12. :status="status"
  13. :project-path="currentProjectPath"
  14. v-on:close="window.menu = false"></side-navigation-bar>
  15. <!-- actual content -->
  16. <div class="content">
  17. <project-open-window v-if="!currentProject"
  18. :projects="projects"
  19. :status="status"
  20. :socket="socket"
  21. v-on:open="show('settings')"/>
  22. <template v-else>
  23. <project-settings-window v-if="window.content === 'settings'"
  24. :current-project="currentProject"
  25. :current-project-path="currentProjectPath"
  26. :status="status"
  27. :socket="socket"/>
  28. </template>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import io from "socket.io-client";
  35. import ProjectOpenWindow from "@/components/projects/project-open-window";
  36. import TopNavigationBar from "@/components/window/top-navigation-bar";
  37. import SideNavigationBar from "@/components/window/side-navigation-bar";
  38. import ProjectSettingsWindow from "@/components/projects/project-settings-window";
  39. export default {
  40. name: 'App',
  41. components: {
  42. ProjectSettingsWindow,
  43. SideNavigationBar,
  44. TopNavigationBar,
  45. ProjectOpenWindow
  46. },
  47. data: function() {
  48. return {
  49. // initialize socket.io connection
  50. socket: {
  51. io: io('http://' + window.location.hostname + ':5000'),
  52. set: function(path, value) {
  53. this.io.emit('set', {path: path, value: value});
  54. },
  55. add: function(path, value) {
  56. this.io.emit('add', {path: path, value: value});
  57. }
  58. },
  59. status: null,
  60. window: {
  61. wide: true,
  62. menu: false,
  63. content: 'settings',
  64. }
  65. }
  66. },
  67. computed: {
  68. projects: function() {
  69. return this.status == null ? [] : this.status.projects;
  70. },
  71. currentProject: function() {
  72. for (let i = 0; i < this.projects.length; i++)
  73. if (this.projects[i].status === 'open')
  74. return this.projects[i];
  75. return false;
  76. },
  77. currentProjectPath: function() {
  78. for (let i = 0; i < this.projects.length; i++)
  79. if (this.projects[i].status === 'open')
  80. return 'projects/' + i;
  81. return false;
  82. }
  83. },
  84. methods: {
  85. resize: function() {
  86. this.window.wide = (document.body.offsetWidth > 1024);
  87. },
  88. show: function(value) {
  89. this.window.content = value;
  90. }
  91. },
  92. created: function() {
  93. this.socket.io.on('app_status', status => this.status = status);
  94. window.addEventListener('resize', this.resize);
  95. this.resize();
  96. },
  97. destroyed: function() {
  98. window.removeEventListener('resize', this.resize);
  99. }
  100. }
  101. </script>
  102. <style scoped>
  103. #app {
  104. width: 100%;
  105. height: 100%;
  106. display: flex;
  107. flex-direction: column;
  108. }
  109. .bottom {
  110. display: flex;
  111. flex-grow: 1;
  112. flex-direction: row;
  113. width: 100%;
  114. position: relative;
  115. }
  116. .content {
  117. flex-grow: 1;
  118. overflow: hidden;
  119. }
  120. .content > * {
  121. width: 100%;
  122. height: 100%;
  123. }
  124. </style>