Skip to content

Commit

Permalink
fix #40 #41 (partial)
Browse files Browse the repository at this point in the history
  • Loading branch information
eldertek committed Feb 14, 2024
1 parent 8ceb0fe commit 5977f11
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## 1.1.5 - 2024-02-12
### Added
- Limit number of errors/success messages to 2
- Limit number of fetched duplicates to 20
### Fixed
- Fix an issue where nodeid was not corectly returned by the api
- Fix an issue where duplicates returned was not the user's one
- Fix [#41](https://github.com/eldertek/duplicatefinder/issues/41)
- Fix [#40](https://github.com/eldertek/duplicatefinder/issues/40)
- Fix [#38](https://github.com/eldertek/duplicatefinder/issues/38)
- Fix [#37](https://github.com/eldertek/duplicatefinder/issues/37)
### Changed
Expand Down
2 changes: 1 addition & 1 deletion js/duplicatefinder-main.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/Service/FileInfoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OC\User\NoUserException;
use Symfony\Component\Console\Output\OutputInterface;

use OCA\DuplicateFinder\AppInfo\Application;
Expand Down
57 changes: 41 additions & 16 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<NcContent app-name="duplicatefinder">
<NcAppNavigation v-if="(acknowledgedDuplicates.length > 0 || unacknowledgedDuplicates.length > 0) && !loading">
<template #list>
<NcAppNavigationItem name="Uncknowledged" :allowCollapse="true" :open="true">
<NcAppNavigationItem name="Unacknowledged" :allowCollapse="true" :open="true">
<template #icon>
<CloseCircle :size="20" />
</template>
Expand Down Expand Up @@ -109,6 +109,7 @@ export default {
currentDuplicateId: null,
updating: false,
fetchingLimit: 1,
loading: true,
loadingDots: '',
loadingInterval: null,
Expand Down Expand Up @@ -155,10 +156,26 @@ export default {
},
async mounted() {
this.startLoadingAnimation();
this.fetchAllPages('acknowledged');
this.fetchAllPages('unacknowledged');
this.fetchAllPages('acknowledged', this.fetchingLimit, true);
this.fetchAllPages('unacknowledged', this.fetchingLimit, true);
this.stopLoadingAnimation();
},
watch: {
// Watcher for acknowledgedDuplicates list
acknowledgedDuplicates(newVal) {
if (newVal.length <= 2) {
// Trigger re-fetch for acknowledged list with the existing limit, not initial fetch
this.fetchAllPages('acknowledged', this.fetchingLimit, false);
}
},
// Watcher for unacknowledgedDuplicates list
unacknowledgedDuplicates(newVal) {
if (newVal.length <= 2) {
// Trigger re-fetch for unacknowledged list with the existing limit, not initial fetch
this.fetchAllPages('unacknowledged', this.fetchingLimit, false);
}
}
},
methods: {
openFileInViewer(file) {
// Ensure the viewer script is loaded and OCA.Viewer is available
Expand Down Expand Up @@ -224,20 +241,21 @@ export default {
this.loadingDots = ''; // Reset loading dots
},
async fetchAllPages(type) {
async fetchAllPages(type, limit, initial) {
let currentPage = 1;
let url;
this.loading = true;
do {
// Determine URL based on the type
if (type === 'acknowledged') {
url = generateUrl(`/apps/duplicatefinder/api/duplicates/acknowledged?page=${currentPage}`);
url = generateUrl(`/apps/duplicatefinder/api/duplicates/acknowledged?page=${currentPage}&limit=${limit}`);
} else if (type === 'unacknowledged') {
url = generateUrl(`/apps/duplicatefinder/api/duplicates/unacknowledged?page=${currentPage}`);
url = generateUrl(`/apps/duplicatefinder/api/duplicates/unacknowledged?page=${currentPage}&limit=${limit}`);
} else {
console.error('Invalid type');
showError(t('duplicatefinder', 'Could not fetch duplicates'));
this.showError(t('duplicatefinder', 'Could not fetch duplicates'));
this.loading = false;
return;
}
Expand All @@ -246,26 +264,34 @@ export default {
const newDuplicates = response.data.entities;
const pagination = response.data.pagination;
if (type === 'acknowledged') {
this.acknowledgedDuplicates = [...this.acknowledgedDuplicates, ...newDuplicates];
this.totalPagesAcknowledged = pagination.totalPages;
// Decide to append new duplicates or replace based on `initial` flag
if (initial) {
// Replace or set the list if it's the initial fetch
this[type + 'Duplicates'] = newDuplicates.slice(0, limit);
} else {
this.unacknowledgedDuplicates = [...this.unacknowledgedDuplicates, ...newDuplicates];
this.totalPagesUnacknowledged = pagination.totalPages;
// Append new duplicates and ensure unique entries, if needed
this[type + 'Duplicates'] = [...this[type + 'Duplicates'], ...newDuplicates].slice(0, limit);
}
// Update pagination details
this[`totalPages${type.charAt(0).toUpperCase() + type.slice(1)}`] = pagination.totalPages;
currentPage++;
// Break out if the limit is reached
if (this[type + 'Duplicates'].length >= limit) {
console.log(`Limit of ${limit} reached for ${type} duplicates, stopping fetch.`);
break;
}
} catch (e) {
console.error(e);
showError(t('duplicatefinder', `Could not fetch ${type} duplicates`));
this.showError(t('duplicatefinder', `Could not fetch ${type} duplicates`));
this.loading = false;
return;
}
} while (currentPage <= this[`totalPages${type.charAt(0).toUpperCase() + type.slice(1)}`]);
this.loading = false;
},
async acknowledgeDuplicate() {
try {
const hash = this.currentDuplicate.hash;
Expand Down Expand Up @@ -391,7 +417,6 @@ export default {
this.currentDuplicateId = null; // If no more hashes are left in the current list
}
}
} catch (e) {
console.error(e);
this.showError(t('duplicatefinder', `Could not delete the duplicate at path: ${item.path}`));
Expand Down

0 comments on commit 5977f11

Please sign in to comment.