ComparisonView.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div class="container">
  3. <button id="show-button" :class="{hidden : !hideLeftPanel}" @click="togglePanel" title="Show sidebar">
  4. <img src="@/assets/double_arrow_black_24dp.svg" alt="show">
  5. </button>
  6. <div id="sidebar" :class="{ hidden : hideLeftPanel }">
  7. <div class="title-section">
  8. <h1>JPlag Comparison</h1>
  9. <button id="hide-button" @click="togglePanel" title="Hide sidebar">
  10. <img src="@/assets/keyboard_double_arrow_left_black_24dp.svg" alt="hide"></button>
  11. </div>
  12. <TextInformation label="Submission 1" :value="id1" :anonymous="store.state.anonymous.has(id1)"/>
  13. <TextInformation label="Submission 2" :value="id2" :anonymous="store.state.anonymous.has(id2)"/>
  14. <TextInformation label="Match %" :value="comparison.match_percentage"/>
  15. <MatchTable :matches="comparison.allMatches" :id1="id1" :id2="id2" @match-selected="showMatch" />
  16. </div>
  17. <FilesContainer :matches="comparison.matchesInFirstSubmission" :files="filesOfFirst" :container-id="1"
  18. files-owner="Submission 1"
  19. @toggle-collapse="toggleCollapseFirst"
  20. @line-selected="showMatchInSecond"/>
  21. <FilesContainer :matches="comparison.matchesInSecondSubmissions" :files="filesOfSecond" :container-id="2"
  22. files-owner="Submission 2"
  23. @toggle-collapse="toggleCollapseSecond"
  24. @line-selected="showMatchInFirst"/>
  25. </div>
  26. </template>
  27. <script>
  28. import { defineComponent, ref } from "vue";
  29. import {generateLineCodeLink} from "@/utils/Utils";
  30. import store from "@/store/store";
  31. import TextInformation from "@/components/TextInformation";
  32. import MatchTable from "@/components/MatchTable";
  33. import {ComparisonFactory} from "@/model/factories/ComparisonFactory";
  34. import FilesContainer from "@/components/FilesContainer";
  35. export default defineComponent({
  36. name: "ComparisonView",
  37. components: {FilesContainer, MatchTable, TextInformation },
  38. props: {
  39. id1: {
  40. type: String,
  41. },
  42. id2: {
  43. type: String,
  44. },
  45. },
  46. setup(props) {
  47. /**
  48. * Name of the comparison file. Comparison files should be named {ID1}-{ID2}
  49. * @type {string}
  50. */
  51. const fileName = props.id1.concat("-").concat(props.id2)
  52. let comparison;
  53. //getting the comparison file based on the used mode (zip, local, single)
  54. if(store.state.local) {
  55. // eslint-disable-next-line @typescript-eslint/no-var-requires
  56. comparison = ComparisonFactory.getComparison(require(`../files/${fileName}.json`))
  57. } else if(store.state.zip) {
  58. comparison = ComparisonFactory.getComparison(JSON.parse(store.state.files[fileName.concat(".json")]))
  59. } else if(store.state.single) {
  60. comparison = ComparisonFactory.getComparison(JSON.parse(store.state.fileString))
  61. }
  62. const filesOfFirst = ref(comparison.filesOfFirstSubmission)
  63. const filesOfSecond = ref(comparison.filesOfSecondSubmission)
  64. /**
  65. * Collapses a file in the first files container.
  66. * @param title
  67. */
  68. const toggleCollapseFirst = (title) => { filesOfFirst.value[title].collapsed = !filesOfFirst.value[title].collapsed }
  69. /**
  70. * Collapses a file in the second files container.
  71. * @param title
  72. */
  73. const toggleCollapseSecond = (title) => { filesOfSecond.value[title].collapsed = !filesOfSecond.value[title].collapsed }
  74. /**
  75. * Shows a match in the first files container
  76. * @param e
  77. * @param panel
  78. * @param file
  79. * @param line
  80. */
  81. const showMatchInFirst = ( e, panel, file, line ) => {
  82. if( !filesOfFirst.value[file].collapsed ) { toggleCollapseFirst(file) }
  83. document.getElementById(generateLineCodeLink(panel, file, line)).scrollIntoView()
  84. }
  85. /**
  86. * Shows a match in the second files container.
  87. * @param e
  88. * @param panel
  89. * @param file
  90. * @param line
  91. */
  92. const showMatchInSecond = ( e, panel, file, line ) => {
  93. if( !filesOfSecond.value[file].collapsed ) { toggleCollapseSecond(file) }
  94. document.getElementById(generateLineCodeLink(panel, file, line)).scrollIntoView()
  95. }
  96. const showMatch = ( e, match ) => {
  97. showMatchInFirst(e, 1, match.firstFile, match.startInFirst)
  98. showMatchInSecond(e, 2, match.secondFile, match.startInSecond)
  99. }
  100. //Left panel
  101. const hideLeftPanel = ref(true)
  102. const togglePanel = () => {
  103. hideLeftPanel.value = !hideLeftPanel.value
  104. }
  105. return {
  106. comparison,
  107. filesOfFirst,
  108. filesOfSecond,
  109. hideLeftPanel,
  110. toggleCollapseFirst,
  111. toggleCollapseSecond,
  112. showMatchInFirst,
  113. showMatchInSecond,
  114. showMatch,
  115. togglePanel,
  116. store
  117. }
  118. }
  119. })
  120. </script>
  121. <style scoped>
  122. h1 {
  123. color: var(--on-primary-color);
  124. text-align: center;
  125. }
  126. .container {
  127. display: flex;
  128. align-items: stretch;
  129. flex-wrap: nowrap;
  130. width: 100%;
  131. height: 100%;
  132. background: var(--background-color);
  133. }
  134. .title-section {
  135. display: flex;
  136. justify-content: space-between;
  137. }
  138. .title-section > h1 {
  139. text-align: left !important;
  140. }
  141. .hidden {
  142. display: none !important;
  143. }
  144. #sidebar {
  145. display: flex;
  146. flex-direction: column;
  147. flex-wrap: nowrap;
  148. width: 60%;
  149. background: var(--primary-color-light);
  150. padding: 1%;
  151. border-top-right-radius: 10px;
  152. border-bottom-right-radius: 10px;
  153. }
  154. #hide-button {
  155. display: flex;
  156. flex-direction: column;
  157. background: transparent;
  158. border-radius: 10px;
  159. height: max-content;
  160. border: none;
  161. }
  162. #hide-button:hover {
  163. cursor: pointer;
  164. background: var(--primary-color-dark);
  165. }
  166. #show-button {
  167. position: absolute;
  168. z-index: 1000;
  169. left: 0;
  170. background: var(--secondary-color);
  171. border: none;
  172. border-top-right-radius: 10px;
  173. border-bottom-right-radius: 10px;
  174. height: 100%;
  175. width: 1%;
  176. }
  177. #show-button img {
  178. display: none;
  179. }
  180. #show-button:hover {
  181. cursor: pointer;
  182. width: 3%;
  183. }
  184. #show-button:hover img {
  185. display: block;
  186. }
  187. </style>