diff --git a/frontend/src/components/c-file-type-checkboxes.vue b/frontend/src/components/c-file-type-checkboxes.vue new file mode 100644 index 0000000000..263d4bcdf9 --- /dev/null +++ b/frontend/src/components/c-file-type-checkboxes.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/frontend/src/views/c-authorship.vue b/frontend/src/views/c-authorship.vue index d0b18c3c09..5cdbcdd5d1 100644 --- a/frontend/src/views/c-authorship.vue +++ b/frontend/src/views/c-authorship.vue @@ -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  - span {{ totalLineCount }}  - span ({{ totalLineCount - totalBlankLineCount }})  - 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 }} {{ fileTypeLinesObj[fileType] }}  - span ({{ fileTypeLinesObj[fileType] - fileTypeBlankLinesObj[fileType] }})  - 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( @@ -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'; @@ -126,22 +115,22 @@ const filesSortDict = { }; function authorshipInitialState(): { - isLoaded: boolean, - selectedFiles: Array, - filterType: FilterType, - selectedFileTypes: Array, - fileTypes: Array - filesLinesObj: { [key: string]: number} - fileTypeBlankLinesObj: { [key: string]: number }, - filesSortType: FilesSortType, - toReverseSortFiles: boolean, - isBinaryFilesChecked: boolean, - isIgnoredFilesChecked: boolean, - searchBarValue: string, - authorDisplayName: string, - authors: Set, - selectedColors: Array - } { + isLoaded: boolean, + selectedFiles: Array, + filterType: FilterType, + selectedFileTypes: Array, + fileTypes: Array + filesLinesObj: { [key: string]: number } + fileTypeBlankLinesObj: { [key: string]: number }, + filesSortType: FilesSortType, + toReverseSortFiles: boolean, + isBinaryFilesChecked: boolean, + isIgnoredFilesChecked: boolean, + searchBarValue: string, + authorDisplayName: string, + authors: Set, + selectedColors: Array + } { return { isLoaded: false, selectedFiles: [] as Array, @@ -168,6 +157,7 @@ export default defineComponent({ name: 'c-authorship', components: { cAuthorshipFile, + cFileTypeCheckboxes, }, mixins: [brokenLinkDisabler], emits: [ @@ -179,7 +169,7 @@ export default defineComponent({ filterType: FilterType, selectedFileTypes: Array, fileTypes: Array - filesLinesObj: { [key: string]: number} + filesLinesObj: { [key: string]: number } fileTypeBlankLinesObj: { [key: string]: number }, filesSortType: FilesSortType, toReverseSortFiles: boolean, @@ -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; @@ -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, @@ -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, + }; }, }, }); diff --git a/frontend/src/views/c-summary.vue b/frontend/src/views/c-summary.vue index 3d6b8e68d1..777ec86c48 100644 --- a/frontend/src/views/c-summary.vue +++ b/frontend/src/views/c-summary.vue @@ -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:  - 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", @@ -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 { @@ -169,6 +160,7 @@ export default defineComponent({ name: 'c-summary', components: { cSummaryCharts, + cFileTypeCheckboxes, }, props: { repos: { @@ -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; @@ -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, ); @@ -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; }, }, }); diff --git a/frontend/src/views/c-zoom.vue b/frontend/src/views/c-zoom.vue index 5552b02feb..af521cbfa5 100644 --- a/frontend/src/views/c-zoom.vue +++ b/frontend/src/views/c-zoom.vue @@ -65,23 +65,13 @@ option(v-bind:value='true') Descending option(v-bind:value='false') Ascending label order - .fileTypes - .checkboxes.mui-form--inline(v-if="fileTypes.length > 0") - label(style='background-color: #000000; color: #ffffff') - input.mui-checkbox--fileType(type="checkbox", v-model="isSelectAllChecked", value="all") - span All  - label( - v-for="fileType 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-on:change="updateSelectedFileTypesHash", v-model="selectedFileTypes") - span {{ fileType }}   + 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="updateSelectedFileTypesHash" + ) .zoom__day(v-for="day in selectedCommits", v-bind:key="day.date") h3(v-if="info.zTimeFrame === 'week'") Week of {{ day.date }} @@ -100,6 +90,7 @@ import brokenLinkDisabler from '../mixin/brokenLinkMixin'; import tooltipPositioner from '../mixin/dynamicTooltipMixin'; import cRamp from '../components/c-ramp.vue'; import cZoomCommitMessage from '../components/c-zoom-commit-message.vue'; +import cFileTypeCheckboxes from '../components/c-file-type-checkboxes.vue'; import { Commit, CommitResult, @@ -136,6 +127,7 @@ export default defineComponent({ FontAwesomeIcon, cRamp, cZoomCommitMessage, + cFileTypeCheckboxes, }, mixins: [brokenLinkDisabler, tooltipPositioner], data(): { @@ -204,7 +196,7 @@ export default defineComponent({ }, selectedCommits(): Array { - if (this.isSelectAllChecked) { + if (this.isSelectAllChecked()) { return this.filteredUser?.commits ?? []; } @@ -242,19 +234,6 @@ export default defineComponent({ prev + commit.commitResults.filter((slice) => slice.isOpen).length ), 0); }, - 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.updateSelectedFileTypesHash(); - }, - }, ...mapState({ fileTypeColors: (state: unknown) => (state as StoreState).fileTypeColors, @@ -344,6 +323,9 @@ export default defineComponent({ .filter((fileType) => this.fileTypes.includes(fileType)); } }, + isSelectAllChecked(): boolean { + return this.selectedFileTypes.length === this.fileTypes.length; + }, updateSelectedFileTypesHash(): void { const fileTypeHash = this.selectedFileTypes.length > 0 ? this.selectedFileTypes.reduce((a, b) => `${a}~${b}`) @@ -396,9 +378,6 @@ export default defineComponent({ window.removeHash('zFR'); window.encodeHash(); }, - getFontColor(color: string): string { - return window.getFontColor(color); - }, }, });