Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2001] Extract c-file-type-checkboxes from Summary, Authorship and Zoom #2173

Merged
merged 29 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7fcf0af
Setup checkbox file
sopa301 Mar 25, 2024
155e368
Try to extract checkboxes
sopa301 Mar 25, 2024
9812c3d
Fix style
sopa301 Mar 25, 2024
334c911
Fix style
sopa301 Mar 25, 2024
1de3ff7
Fix failing test
sopa301 Mar 25, 2024
9d7dc8b
Refactor authorship
sopa301 Mar 26, 2024
bcd34b2
Merge branch 'master' of https://github.com/sopa301/RepoSense into 20…
sopa301 Mar 26, 2024
e5986e9
Fix style
sopa301 Mar 26, 2024
ae756ec
Fix style
sopa301 Mar 26, 2024
a585f07
Fix style
sopa301 Mar 26, 2024
9dfc322
Fix style
sopa301 Mar 26, 2024
e68c6e5
Refactor summary
sopa301 Mar 26, 2024
f54ab0c
Remove unused function
sopa301 Mar 26, 2024
30f2647
Fix style
sopa301 Mar 26, 2024
0403af7
Refactor unused functions
sopa301 Mar 26, 2024
1675a19
Merge branch 'master' of https://github.com/reposense/RepoSense into …
sopa301 Apr 6, 2024
8ae8cfb
Merge branch 'master' of https://github.com/reposense/RepoSense into …
sopa301 Apr 13, 2024
4c8246f
Fix style
sopa301 Apr 13, 2024
e66ceb5
Merge missed changes
sopa301 Apr 13, 2024
4d1884c
Fix bug in element title
sopa301 Apr 13, 2024
faa83a4
Refactor code to move away from v-html
sopa301 Apr 13, 2024
6623d56
Fix style
sopa301 Apr 13, 2024
88ef5df
Merge branch 'master' into 2001-checkbox
sopa301 Apr 15, 2024
57a8bfb
Abstract file hashes from checkbox component
sopa301 Apr 17, 2024
60b3e6b
Merge branch '2001-checkbox' of https://github.com/sopa301/RepoSense …
sopa301 Apr 17, 2024
8c73cdf
Fix naming of emit listeners
sopa301 Apr 17, 2024
b271257
Rename checkboxes file
sopa301 Apr 19, 2024
192c98d
Fix bug
sopa301 Apr 19, 2024
cae363d
Merge branch 'master' into 2001-checkbox
sopa301 Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions frontend/src/components/c-file-type-checkboxes.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template lang="pug">
.checkboxes.mui-form--inline(v-if="fileTypes.length > 0")
label.all-checkbox
input.mui-checkbox--fileType#all(type="checkbox", v-model="isAllChecked", value="all")
span(v-if="allCheckboxLabel", v-bind:title="getTitle(allCheckboxLabel)")
span {{ getLabel(allCheckboxLabel) }}
span(v-else) All&nbsp;
label(
v-for="fileType, index in fileTypes",
v-bind:key="fileType",
v-bind:style="{\
'background-color': fileTypeColors[fileType],\
'color': getFontColor(fileTypeColors[fileType])\
}"
)
input.mui-checkbox--fileType(type="checkbox", v-bind:value="fileType",
v-model="localSelectedFileTypes", v-bind:id="fileType")
span(v-if="fileTypeCheckboxLabels", v-bind:title="getTitle(fileTypeCheckboxLabels[index])")
span {{ getLabel(fileTypeCheckboxLabels[index]) }}
span(v-else) {{ this.fileTypes[index] }}&nbsp;
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue';

export default defineComponent({
name: 'c-file-type-checkboxes',
props: {
fileTypes: {
type: Array as PropType<Array<string>>,
required: true,
},
fileTypeColors: {
type: Object as PropType<Record<string, string>>,
required: true,
},
selectedFileTypes: {
type: Array as PropType<Array<string>>,
required: true,
},
allCheckboxLabel: {
type: Object as PropType<{
fileTitle: string,
fileType: string,
lineCount: number,
blankLineCount: number,
}>,
default: undefined,
},
fileTypeCheckboxLabels: {
type: Array as PropType<Array<{
fileTitle: string,
fileType: string,
lineCount: number,
blankLineCount: number,
}>>,
default: undefined,
},
},
emits: ['update:selectedFileTypes', 'select-all-checked'],
computed: {
isAllChecked: {
get(): boolean {
return this.selectedFileTypes.length === this.fileTypes.length;
},
set(value: boolean): void {
if (value) {
this.localSelectedFileTypes = this.fileTypes.slice();
} else {
this.localSelectedFileTypes = [];
}
this.$emit('select-all-checked', value);
},
},
localSelectedFileTypes: {
get(): Array<string> {
return this.selectedFileTypes;
},
set(value: Array<string>): void {
this.$emit('update:selectedFileTypes', value);
},
},
},
methods: {
getFontColor(color: string): string {
return window.getFontColor(color);
},
getTitle(label: {
fileTitle: string,
fileType: string,
lineCount: number,
blankLineCount: number,
}): string {
return `${label.fileTitle}: Blank: ${label.blankLineCount}, `
+ `Non-Blank: ${label.lineCount - label.blankLineCount}`;
},
getLabel(label: {
fileTitle: string,
fileType: string,
lineCount: number,
blankLineCount: number,
}): string {
return `${label.fileType}\xA0\xA0`
+ `${label.blankLineCount}\xA0\xA0`
+ `(${label.lineCount - label.blankLineCount})\xA0`;
Comment on lines +103 to +105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sopa301 This must be showing "Line count (Line count - blank line count)", but this is "Blank line count (Line count - blank line count)" instead.

Suggested change
return `${label.fileType}\xA0\xA0`
+ `${label.blankLineCount}\xA0\xA0`
+ `(${label.lineCount - label.blankLineCount})\xA0`;
return `${label.fileType}\xA0\xA0`
+ `${label.lineCount}\xA0\xA0`
+ `(${label.lineCount - label.blankLineCount})\xA0`;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I'll create a PR to fix it!

},
},
});
</script>

<style lang="scss" scoped>
.all-checkbox {
background-color: #000000;
color: #ffffff;
}

.mui-checkbox--fileType {
vertical-align: middle;
}
</style>
129 changes: 65 additions & 64 deletions frontend/src/views/c-authorship.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,15 @@
v-model="filterType",
v-on:change="indicateCheckBoxes"
)
.checkboxes.mui-form--inline(v-if="info.files.length > 0")
label(style='background-color: #000000; color: #ffffff')
input.mui-checkbox--fileType#all(type="checkbox", v-model="isSelectAllChecked")
span(v-bind:title="getTotalFileBlankLineInfo()")
span All&nbsp;
span {{ totalLineCount }}&nbsp;
span ({{ totalLineCount - totalBlankLineCount }})&nbsp;
template(v-for="fileType in Object.keys(fileTypeLinesObj)", v-bind:key="fileType")
label(
v-bind:style="{\
'background-color': fileTypeColors[fileType],\
'color': getFontColor(fileTypeColors[fileType])\
}"
)
input.mui-checkbox--fileType(type="checkbox",
v-bind:id="fileType", v-bind:value="fileType",
v-on:change="indicateCheckBoxes", v-model="selectedFileTypes")
span(v-bind:title="getFileTypeBlankLineInfo(fileType)")
span {{ fileType }}&nbsp;{{ fileTypeLinesObj[fileType] }}&nbsp;
span ({{ fileTypeLinesObj[fileType] - fileTypeBlankLinesObj[fileType] }})&nbsp;
br
c-file-type-checkboxes(
v-bind:file-types="fileTypes",
v-bind:file-type-colors="fileTypeColors",
v-model:selected-file-types="selectedFileTypes",
@update:selected-file-types="indicateCheckBoxes",
v-bind:all-checkbox-label="allCheckboxLabel",
v-bind:file-type-checkbox-labels="checkboxLabels"
)
.checkboxes.mui-form--inline
label.binary-fileType(v-if="binaryFilesCount > 0")
input.mui-checkbox--fileType(type="checkbox", v-model="isBinaryChecked")
span(
Expand Down Expand Up @@ -112,6 +100,7 @@ import { mapState } from 'vuex';
import { minimatch } from 'minimatch';
import brokenLinkDisabler from '../mixin/brokenLinkMixin';
import cAuthorshipFile from '../components/c-authorship-file.vue';
import cFileTypeCheckboxes from '../components/c-file-type-checkboxes.vue';
import getNonRepeatingColor from '../utils/random-color-generator';
import { StoreState } from '../types/vuex.d';
import { FileResult, Line } from '../types/zod/authorship-type';
Expand All @@ -126,22 +115,22 @@ const filesSortDict = {
};

function authorshipInitialState(): {
isLoaded: boolean,
selectedFiles: Array<AuthorshipFile>,
filterType: FilterType,
selectedFileTypes: Array<string>,
fileTypes: Array<string>
filesLinesObj: { [key: string]: number}
fileTypeBlankLinesObj: { [key: string]: number },
filesSortType: FilesSortType,
toReverseSortFiles: boolean,
isBinaryFilesChecked: boolean,
isIgnoredFilesChecked: boolean,
searchBarValue: string,
authorDisplayName: string,
authors: Set<string>,
selectedColors: Array<string>
} {
isLoaded: boolean,
selectedFiles: Array<AuthorshipFile>,
filterType: FilterType,
selectedFileTypes: Array<string>,
fileTypes: Array<string>
filesLinesObj: { [key: string]: number }
fileTypeBlankLinesObj: { [key: string]: number },
filesSortType: FilesSortType,
toReverseSortFiles: boolean,
isBinaryFilesChecked: boolean,
isIgnoredFilesChecked: boolean,
searchBarValue: string,
authorDisplayName: string,
authors: Set<string>,
selectedColors: Array<string>
} {
return {
isLoaded: false,
selectedFiles: [] as Array<AuthorshipFile>,
Expand All @@ -168,6 +157,7 @@ export default defineComponent({
name: 'c-authorship',
components: {
cAuthorshipFile,
cFileTypeCheckboxes,
},
mixins: [brokenLinkDisabler],
emits: [
Expand All @@ -179,7 +169,7 @@ export default defineComponent({
filterType: FilterType,
selectedFileTypes: Array<string>,
fileTypes: Array<string>
filesLinesObj: { [key: string]: number}
filesLinesObj: { [key: string]: number }
fileTypeBlankLinesObj: { [key: string]: number },
filesSortType: FilesSortType,
toReverseSortFiles: boolean,
Expand All @@ -199,21 +189,6 @@ export default defineComponent({
* window.comparator(filesSortDict[this.filesSortType])(a, b);
},

isSelectAllChecked: {
get(): boolean {
return this.selectedFileTypes.length === this.fileTypes.length;
},
set(value: boolean): void {
if (value) {
this.selectedFileTypes = this.fileTypes.slice();
} else {
this.selectedFileTypes = [];
}

this.indicateCheckBoxes();
},
},

isBinaryChecked: {
get(): boolean {
return this.isBinaryFilesChecked;
Expand Down Expand Up @@ -276,6 +251,31 @@ export default defineComponent({
return this.info.files.filter((file) => file.isIgnored).length;
},

allCheckboxLabel(): {
fileTitle: string,
fileType: string,
lineCount: number,
blankLineCount: number,
} {
return this.getCheckboxDetails('Total', 'All', this.totalLineCount, this.totalBlankLineCount);
},

checkboxLabels(): Array<{
fileTitle: string,
fileType: string,
lineCount: number,
blankLineCount: number,
}> {
return this.fileTypes.map(
(fileType) => this.getCheckboxDetails(
fileType,
fileType,
this.fileTypeLinesObj[fileType],
this.fileTypeBlankLinesObj[fileType],
),
);
},

...mapState({
fileTypeColors: (state: unknown) => (state as StoreState).fileTypeColors,
info: (state: unknown) => (state as StoreState).tabAuthorshipInfo,
Expand Down Expand Up @@ -637,17 +637,18 @@ export default defineComponent({
this.updateFileTypeHash();
},

getFileTypeBlankLineInfo(fileType: string): string {
return `${fileType}: Blank: ${this.fileTypeBlankLinesObj[fileType]},
Non-Blank: ${this.filesLinesObj[fileType] - this.fileTypeBlankLinesObj[fileType]}`;
},

getTotalFileBlankLineInfo(): string {
return `Total: Blank: ${this.totalBlankLineCount}, Non-Blank: ${this.totalLineCount - this.totalBlankLineCount}`;
},

getFontColor(color: string): string {
return window.getFontColor(color);
getCheckboxDetails(fileTitle: string, fileType: string, lineCount: number, blankLineCount: number): {
fileTitle: string,
fileType: string,
lineCount: number,
blankLineCount: number,
} {
return {
fileTitle,
fileType,
lineCount,
blankLineCount,
};
},
},
});
Expand Down
50 changes: 14 additions & 36 deletions frontend/src/views/c-summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,13 @@
a(v-if="!errorIsShowingMore", v-on:click="toggleErrorShowMore()") SHOW ALL...
a(v-else, v-on:click="toggleErrorShowMore()") SHOW LESS...
.fileTypes(v-if="filterBreakdown && !isWidgetMode")
.checkboxes.mui-form--inline(v-if="Object.keys(fileTypeColors).length > 0")
label(style='background-color: #000000; color: #ffffff')
input.mui-checkbox--fileType#all(type="checkbox", v-model="checkAllFileTypes")
span All:&nbsp;
template(v-for="fileType in Object.keys(fileTypeColors)", v-bind:key="fileType")
label(
v-bind:style="{ 'background-color': fileTypeColors[fileType], \
'color': getFontColor(fileTypeColors[fileType])}"
)
input.mui-checkbox--fileType(
type="checkbox",
v-bind:id="fileType",
v-bind:value="fileType",
v-model="checkedFileTypes",
v-on:change="getFiltered"
)
span {{ fileType }}
c-file-type-checkboxes(
v-bind:file-types="fileTypes",
v-bind:file-type-colors="fileTypeColors",
v-model:selected-file-types="checkedFileTypes",
@update:selected-file-types="getFiltered"
)

c-summary-charts(
v-bind:filtered="filtered",
v-bind:checked-file-types="checkedFileTypes",
Expand All @@ -142,6 +132,7 @@ import { mapState } from 'vuex';
import { PropType, defineComponent } from 'vue';

import cSummaryCharts from '../components/c-summary-charts.vue';
import cFileTypeCheckboxes from '../components/c-file-type-checkboxes.vue';
import getNonRepeatingColor from '../utils/random-color-generator';
import sortFiltered from '../utils/repo-sorter';
import {
Expand Down Expand Up @@ -169,6 +160,7 @@ export default defineComponent({
name: 'c-summary',
components: {
cSummaryCharts,
cFileTypeCheckboxes,
},
props: {
repos: {
Expand Down Expand Up @@ -246,20 +238,6 @@ export default defineComponent({
};
},
computed: {
checkAllFileTypes: {
get(): boolean {
return this.checkedFileTypes.length === this.fileTypes.length;
},
set(value: boolean): void {
if (value) {
this.checkedFileTypes = this.fileTypes.slice();
} else {
this.checkedFileTypes = [];
}
this.getFiltered();
},
},

avgContributionSize(): number {
let totalLines = 0;
let totalCount = 0;
Expand Down Expand Up @@ -842,7 +820,7 @@ export default defineComponent({
return result;
});

if (!this.checkAllFileTypes) {
if (!this.isAllFileTypesChecked()) {
commitResults = commitResults.filter(
(result) => Object.values(result.fileTypesAndContributionMap).length > 0,
);
Expand Down Expand Up @@ -1010,12 +988,12 @@ export default defineComponent({
return window.getDateStr(datems);
},

getFontColor(color: string) {
return window.getFontColor(color);
toggleErrorShowMore(): void {
this.errorIsShowingMore = !this.errorIsShowingMore;
},

toggleErrorShowMore() {
this.errorIsShowingMore = !this.errorIsShowingMore;
isAllFileTypesChecked(): boolean {
return this.checkedFileTypes.length === this.fileTypes.length;
},
},
});
Expand Down
Loading
Loading