Sfoglia il codice sorgente

[192-webreport] Finished doc, code and project clean up

Evgeni 4 anni fa
parent
commit
687fc0de24

+ 0 - 0
report-viewer/src/assets/double_arrow_white_24dp.svg → report-viewer/src/assets/double_arrow_black_24dp.svg


+ 0 - 1
report-viewer/src/assets/double_arrow_white_18dp.svg

@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 20 20" height="18px" viewBox="0 0 20 20" width="18px" fill="#FFFFFF"><g><rect fill="none" height="20" width="20"/></g><g><g><path d="M15.79,9.71l-2.97-4.16C12.57,5.2,12.18,5,11.76,5c-1.06,0-1.68,1.2-1.06,2.07L12.79,10l-2.09,2.93 c-0.62,0.87,0,2.07,1.06,2.07c0.42,0,0.82-0.2,1.06-0.55l2.97-4.16C15.92,10.12,15.92,9.88,15.79,9.71z"/><path d="M10.79,9.71L7.82,5.55C7.57,5.2,7.18,5,6.76,5C5.69,5,5.07,6.2,5.69,7.07L7.79,10l-2.09,2.93C5.07,13.8,5.69,15,6.76,15 c0.42,0,0.82-0.2,1.06-0.55l2.97-4.16C10.92,10.12,10.92,9.88,10.79,9.71z"/></g></g></svg>

+ 0 - 1
report-viewer/src/assets/keyboard_arrow_down_white_18dp.svg

@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" height="18px" viewBox="0 0 24 24" width="18px" fill="#FFFFFF"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/></svg>

+ 0 - 1
report-viewer/src/assets/keyboard_double_arrow_down_white_18dp.svg

@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 20 20" height="18px" viewBox="0 0 20 20" width="18px" fill="#FFFFFF"><g><rect fill="none" height="20" width="20"/></g><g><g><polygon points="15,5.06 13.94,4 10,7.94 6.06,4 5,5.06 10,10.06"/><polygon points="15,11 13.94,9.94 10,13.88 6.06,9.94 5,11 10,16"/></g></g></svg>

+ 1 - 1
report-viewer/src/assets/keyboard_double_arrow_left_white_18dp.svg → report-viewer/src/assets/keyboard_double_arrow_left_black_18dp.svg

@@ -1,5 +1,5 @@
 <svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 20 20" height="18px" viewBox="0 0 20 20" width="18px"
-     fill="#f3eed9">
+     fill="#0000">
     <g>
         <rect fill="none" height="20" width="20"/>
     </g>

+ 1 - 0
report-viewer/src/assets/keyboard_double_arrow_left_black_24dp.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/><rect fill="none" height="24" width="24"/></g><g><g><path d="M18.29,17.29L18.29,17.29c0.39-0.39,0.39-1.02,0-1.41L14.42,12l3.88-3.88c0.39-0.39,0.39-1.02,0-1.41l0,0 c-0.39-0.39-1.02-0.39-1.41,0l-4.59,4.59c-0.39,0.39-0.39,1.02,0,1.41l4.59,4.59C17.27,17.68,17.9,17.68,18.29,17.29z"/><path d="M11.7,17.29L11.7,17.29c0.39-0.39,0.39-1.02,0-1.41L7.83,12l3.88-3.88c0.39-0.39,0.39-1.02,0-1.41l0,0 c-0.39-0.39-1.02-0.39-1.41,0l-4.59,4.59c-0.39,0.39-0.39,1.02,0,1.41l4.59,4.59C10.68,17.68,11.31,17.68,11.7,17.29z"/></g></g></svg>

+ 0 - 13
report-viewer/src/assets/keyboard_double_arrow_left_white_24dp.svg

@@ -1,13 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px"
-     fill="#f3eed9">
-    <g>
-        <rect fill="none" height="24" width="24"/>
-        <rect fill="none" height="24" width="24"/>
-    </g>
-    <g>
-        <g>
-            <path d="M18.29,17.29L18.29,17.29c0.39-0.39,0.39-1.02,0-1.41L14.42,12l3.88-3.88c0.39-0.39,0.39-1.02,0-1.41l0,0 c-0.39-0.39-1.02-0.39-1.41,0l-4.59,4.59c-0.39,0.39-0.39,1.02,0,1.41l4.59,4.59C17.27,17.68,17.9,17.68,18.29,17.29z"/>
-            <path d="M11.7,17.29L11.7,17.29c0.39-0.39,0.39-1.02,0-1.41L7.83,12l3.88-3.88c0.39-0.39,0.39-1.02,0-1.41l0,0 c-0.39-0.39-1.02-0.39-1.41,0l-4.59,4.59c-0.39,0.39-0.39,1.02,0,1.41l4.59,4.59C10.68,17.68,11.31,17.68,11.7,17.29z"/>
-        </g>
-    </g>
-</svg>

+ 0 - 1
report-viewer/src/assets/keyboard_double_arrow_up_white_18dp.svg

@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 20 20" height="18px" viewBox="0 0 20 20" width="18px" fill="#FFFFFF"><g><rect fill="none" height="20" width="20"/></g><g><g><polygon points="5,14.94 6.06,16 10,12.06 13.94,16 15,14.94 10,9.94"/><polygon points="5,9 6.06,10.06 10,6.12 13.94,10.06 15,9 10,4"/></g></g></svg>

BIN
report-viewer/src/assets/logo.png


+ 2 - 2
report-viewer/src/components/CodePanel.vue

@@ -3,8 +3,8 @@
     <div class="file-title">
       <p style="width: 90%">{{ title }}</p>
       <button style="width: 10%" class="collapse-button" @click="$emit('toggleCollapse')">
-        <img v-if="collapse" src="../assets/keyboard_double_arrow_up_white_18dp.svg" alt="hide info">
-        <img v-else src="../assets/keyboard_double_arrow_down_white_18dp.svg" alt="additional info">
+        <img v-if="collapse" src="../assets/keyboard_double_arrow_up_black_18dp.svg" alt="hide info">
+        <img v-else src="../assets/keyboard_double_arrow_down_black_18dp.svg" alt="additional info">
       </button>
     </div>
     <div class="code-container" :class="{ hidden : !collapse }">

+ 21 - 0
report-viewer/src/components/FilesContainer.vue

@@ -26,18 +26,32 @@ export default defineComponent({
   name: "FilesContainer",
   components: { CodePanel, VueDraggableNext},
   props: {
+    /**
+     * Id of the files container. We have only two so it is either 1 or 2.
+     */
     containerId: {
       type: Number,
       required: true
     },
+    /**
+     * Id of the submission to thich the files belong.
+     */
     filesOwner: {
       type: String,
       required: true
     },
+    /**
+     * Files of the submission.
+     * type: Array<SubmissionFile>
+     */
     files: {
       required: true,
 
     },
+    /**
+     * Matche of submission.
+     * type: Array<MatchInSingleFile>
+     */
     matches: {
       required: true
     }
@@ -45,6 +59,13 @@ export default defineComponent({
 
   setup(props, { emit }) {
 
+    /**
+     * Passes lineSelected event, emitted from LineOfCode, to parent.
+     * @param e
+     * @param index
+     * @param file
+     * @param line
+     */
     const lineSelected = (e, index, file, line) => {
       emit('lineSelected', e, index, file, line)
     }

+ 10 - 0
report-viewer/src/components/MatchTable.vue

@@ -37,12 +37,22 @@ import { defineComponent } from "vue";
 export default defineComponent({
   name: "MatchTable",
   props: {
+    /**
+     * Matches of the comparison.
+     * type: Array<Match>
+     */
     matches : {
       type: Array
     },
+    /**
+     * ID of first submission
+     */
     id1: {
       type: String
     },
+    /**
+     * ID of second submission
+     */
     id2: {
       type: String
     }

+ 3 - 0
report-viewer/src/components/TextInformation.vue

@@ -37,6 +37,9 @@ export default defineComponent({
       type: String,
       default: "",
     },
+    /**
+     * Indicates whether the value should be hidden.
+     */
     anonymous: {
       type: Boolean,
       default: false

+ 3 - 0
report-viewer/src/model/Comparison.ts

@@ -2,6 +2,9 @@ import {Match} from "./Match";
 import {SubmissionFile} from "./SubmissionFile"
 import {MatchInSingleFile} from "./MatchInSingleFile";
 
+/**
+ * Comparison model used by the ComparisonView
+ */
 export class Comparison {
     private readonly _firstSubmissionId: string
     private readonly _secondSubmissionId: string

+ 4 - 0
report-viewer/src/model/ComparisonListElement.ts

@@ -1,3 +1,7 @@
+/**
+ * Comparison model used by the Comparison Table in Overview. Only the needed attributes to display are included.
+ * For full comparison model see Comparison.ts
+ */
 export type ComparisonListElement = {
     firstSubmissionId: string,
     secondSubmissionId: string,

+ 12 - 0
report-viewer/src/model/MatchInSingleFile.ts

@@ -1,8 +1,20 @@
+/**
+ * Describes a match in a single file.
+ */
 export type MatchInSingleFile = {
     start: number,
     end: number,
+    /**
+     * The files container containing the file of the second submission to which this is matched.
+     */
     linked_panel: number,
+    /**
+     * The file name containing the same match in the second submission.
+     */
     linked_file: string,
+    /**
+     * The start of the match in the second file.
+     */
     linked_line: number,
     color: string
 }

+ 6 - 0
report-viewer/src/model/SubmissionFile.ts

@@ -1,4 +1,10 @@
 export type SubmissionFile = {
+    /**
+     * Code lines of the file.
+     */
     lines: Array<string>;
+    /**
+     * Indicates whether the file is displayed or not.
+     */
     collapsed: boolean;
 }

+ 21 - 5
report-viewer/src/store/store.ts

@@ -1,21 +1,37 @@
 import { createStore} from "vuex";
 
+/**
+ * Local store. Stores the state of the application.
+ */
 const store = createStore({
     state () {
         return {
+            /**
+             * The set of ids to be hidden.
+             */
             anonymous : new Set(),
+            /**
+             * Stored files if zip mode is used. Stores the files as key - file name, value - file string
+             */
             files : Object,
+            /**
+             * Indicates whether local mode is used.
+             */
             local: Boolean,
+            /**
+             * Indicates whether zip mode is used.
+             */
             zip: Boolean,
+            /**
+             * Indicates whether single file mode is used.
+             */
             single: Boolean,
+            /**
+             * Files string if single mode is used.
+             */
             fileString: String
         }
     },
-    getters: {
-      getFileByName: (state: any) => (name: string) => {
-          return state.files.find((file: any) => file.name.includes(name))
-      }
-    },
     mutations: {
         addAnonymous (state: any, id) {
             for (let i = 0; i < id.length; i++) {

+ 0 - 20
report-viewer/src/utils/Utils.ts

@@ -2,26 +2,6 @@ export function generateLineCodeLink(index: number, fileName: string, line: numb
     return String(index).concat(fileName).concat(String(line))
 }
 
-export function generateColoringArray(array: Array<Record<string, unknown>>, fileToConsider: number): Array<Record<string, unknown>> {
-    switch (fileToConsider) {
-        case 1:
-            return array.map( m => {
-                //Add connection to second panel via m.start_in_second
-                return { start: m.start_in_first, end: m.end_in_first, link: m.start_in_second, color: m.color}
-            })
-        case 2:
-            return array.map( m => {
-                return { start: m.start_in_second, end: m.end_in_second, link: m.start_in_first, color: m.color}
-            })
-        default:
-            return []
-    }
-}
-
-export function isTrue(str: string): boolean {
-    return str === "true";
-}
-
 export function getFileExtension(file: File): string {
     if(file.name.includes(".")) {
         return file.name.split(".")[1]

+ 31 - 4
report-viewer/src/views/ComparisonView.vue

@@ -1,13 +1,13 @@
 <template>
   <div class="container">
     <button id="show-button" :class="{hidden : !hideLeftPanel}" @click="togglePanel" title="Show sidebar">
-      <img src="@/assets/double_arrow_white_24dp.svg" alt="show">
+      <img src="@/assets/double_arrow_black_24dp.svg" alt="show">
     </button>
     <div id="sidebar" :class="{ hidden : hideLeftPanel }">
       <div class="title-section">
         <h1>JPlag Comparison</h1>
         <button id="hide-button" @click="togglePanel" title="Hide sidebar">
-          <img src="@/assets/keyboard_double_arrow_left_white_24dp.svg" alt="hide"></button>
+          <img src="@/assets/keyboard_double_arrow_left_black_24dp.svg" alt="hide"></button>
       </div>
       <TextInformation label="Submission 1" :value="id1" :anonymous="store.state.anonymous.has(id1)"/>
       <TextInformation label="Submission 2" :value="id2" :anonymous="store.state.anonymous.has(id2)"/>
@@ -46,8 +46,14 @@ export default defineComponent({
     },
   },
   setup(props) {
+    /**
+     * Name of the comparison file. Comparison files should be named {ID1}-{ID2}
+     * @type {string}
+     */
     const fileName = props.id1.concat("-").concat(props.id2)
+
     let comparison;
+    //getting the comparison file based on the used mode (zip, local, single)
     if(store.state.local) {
       // eslint-disable-next-line @typescript-eslint/no-var-requires
       comparison = ComparisonFactory.getComparison(require(`../files/${fileName}.json`))
@@ -60,14 +66,34 @@ export default defineComponent({
     const filesOfFirst = ref(comparison.filesOfFirstSubmission)
     const filesOfSecond = ref(comparison.filesOfSecondSubmission)
 
+    /**
+     * Collapses a file in the first files container.
+     * @param title
+     */
     const toggleCollapseFirst = (title) => { filesOfFirst.value[title].collapsed = !filesOfFirst.value[title].collapsed }
+    /**
+     * Collapses a file in the second files container.
+     * @param title
+     */
     const toggleCollapseSecond = (title) => { filesOfSecond.value[title].collapsed = !filesOfSecond.value[title].collapsed }
-
+    /**
+     * Shows a match in the first files container
+     * @param e
+     * @param panel
+     * @param file
+     * @param line
+     */
     const showMatchInFirst = ( e, panel, file, line ) => {
       if( !filesOfFirst.value[file].collapsed ) { toggleCollapseFirst(file) }
       document.getElementById(generateLineCodeLink(panel, file, line)).scrollIntoView()
     }
-
+    /**
+     * Shows a match in the second files container.
+     * @param e
+     * @param panel
+     * @param file
+     * @param line
+     */
     const showMatchInSecond = ( e, panel, file, line ) => {
       if( !filesOfSecond.value[file].collapsed ) { toggleCollapseSecond(file) }
       document.getElementById(generateLineCodeLink(panel, file, line)).scrollIntoView()
@@ -79,6 +105,7 @@ export default defineComponent({
     }
 
 
+    //Left panel
     const hideLeftPanel = ref(true)
     const togglePanel = () => {
       hideLeftPanel.value = !hideLeftPanel.value

+ 18 - 4
report-viewer/src/views/FileUpload.vue

@@ -24,6 +24,7 @@ export default defineComponent({
   name: "FileUpload",
   setup() {
     let hasLocalFile;
+    //Tries to detect local file. If no files detected, hides local mode from screen.
     try {
       require("../files/overview.json")
       hasLocalFile = true
@@ -31,6 +32,8 @@ export default defineComponent({
       console.log(e)
       hasLocalFile = false
     }
+
+
     const navigateToOverview = () => {
       router.push({
             name: "Overview",
@@ -47,7 +50,10 @@ export default defineComponent({
         }
       })
     }
-
+    /**
+     * Handles zip file on drop. It extracts the zip and saves each file in the store.
+     * @param file
+     */
     const handleZipFile = (file) => {
       jszip.loadAsync(file).then( async (zip) => {
         for (const fileName of Object.keys(zip.files)) {
@@ -61,7 +67,10 @@ export default defineComponent({
         navigateToOverview()
       })
     }
-
+    /**
+     * Handles a json file on drop. It read the file and passes the file string to next window.
+     * @param str
+     */
     const handleJsonFile = (str) => {
       let json = JSON.parse(str)
       if(json["submission_folder_path"]) {
@@ -72,7 +81,10 @@ export default defineComponent({
         navigateToComparisonView(json["first_submission_id"], json["second_submission_id"] )
       }
     }
-
+    /**
+     * Handles file drop.
+     * @param e
+     */
     const uploadFile = (e) => {
       let dropped = e.dataTransfer.files
       if (!dropped) return
@@ -89,7 +101,9 @@ export default defineComponent({
       }
       read.readAsText(files[0])
     }
-
+    /**
+     * Handles click on Continue with local files.
+     */
     const continueWithLocal = () => {
       store.commit("setLoadingType", {local: true, zip: false, single: false, fileString: ""})
       navigateToOverview()

+ 16 - 0
report-viewer/src/views/Overview.vue

@@ -60,6 +60,7 @@ export default defineComponent({
   components: {IDsList, ComparisonsTable, DistributionDiagram, MetricButton, TextInformation },
   setup() {
     let overview;
+    //Gets the overview file based on the used mode (zip, local, single).
     if (store.state.local) {
       try {
         // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -73,6 +74,12 @@ export default defineComponent({
       overview = OverviewFactory.getOverview(JSON.parse(store.state.fileString))
     }
 
+    /**
+     * Handles the selection of an Id to anonymize.
+     * If all submission ids are provided as parameter it hides or displays them based on their previous state.
+     * If a single id is provided it hides all of the other ids except for the chosen one.
+     * @param id
+     */
     const handleId = (id) => {
       if (id.length === overview.submissionIds.length) {
         if (store.state.anonymous.size > 0) {
@@ -95,7 +102,16 @@ export default defineComponent({
 
 
     //Metrics
+    /**
+     * Current metric to display distribution and comparisons for.
+     * @type {Ref<UnwrapRef<boolean[]>>}
+     */
     let selectedMetric = ref(overview.metrics.map(() => false))
+    /**
+     * Index of current selected metric. Used to obtain information for the metric from the distribution and top
+     * comparisons array.
+     * @type {Ref<UnwrapRef<number>>}
+     */
     let selectedMetricIndex = ref(0)
     selectedMetric.value[0] = true;