Skip to content

Commit 1b8ddeb

Browse files
authored
Add reset cache button to advanced project configuration tab (#1781)
* Cache service can now clear entire cache * Add UI for clearing browser storage cache Added a button to the Advanced Configuration section to clear the storage cache, and a short paragraph explaining what it does and why and when one might want to do that. * Make cursor be a pointer on cache reload button * Refresh page after cache reload button clicked
1 parent 7256a1d commit 1b8ddeb

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

src/angular-app/bellows/core/offline/comments-offline-cache.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export class CommentsOfflineCacheService {
1313
return this.offlineCache.deleteObjectInStore('comments', id);
1414
}
1515

16+
deleteAllComments(): angular.IPromise<any> {
17+
return this.offlineCache.clearEntireStore('comments');
18+
}
19+
1620
getAllComments(): angular.IPromise<any> {
1721
return this.offlineCache.getAllFromStore('comments', this.sessionService.projectId());
1822
}

src/angular-app/bellows/core/offline/editor-offline-cache.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export class EditorOfflineCacheService {
1515
return this.offlineCache.deleteObjectInStore('entries', id);
1616
}
1717

18+
deleteAllEntries(): angular.IPromise<any> {
19+
return this.offlineCache.clearEntireStore('entries');
20+
}
21+
1822
getAllEntries(): angular.IPromise<any> {
1923
return this.offlineCache.getAllFromStore('entries', this.sessionService.projectId());
2024
}

src/angular-app/bellows/core/offline/offline-cache.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export class OfflineCacheService {
2020
return this.$q.when(this.getStore(storeName).removeItem(key));
2121
}
2222

23+
clearEntireStore(storeName: string): angular.IPromise<any> {
24+
return this.$q.when(this.getStore(storeName).clear());
25+
}
26+
2327
getAllFromStore(storeName: string, projectId?: string): angular.IPromise<any> {
2428
const results: any[] = [];
2529
return this.$q.when(this.getStore(storeName).iterate<any, any>(value => {

src/angular-app/languageforge/lexicon/settings/configuration/configuration-advanced-options.component.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,16 @@ <h2>Caution!</h2>
44
<p>Please do not change these settings unless asked to by tech support.</p>
55
<label for="updateIntervalSeconds">Update interval (in seconds)</label>
66
<input type="number" ng-model="$ctrl.accPollUpdateTimerSecondsDirty">
7+
<br>
8+
<p>If something went wrong with downloading the dictionary and it only loaded a partial copy (i.e. some dictionary entries are missing), the button below can let you reset the browser storage, removing the partial copy of the dictionary stored in your browser so that you can download it again.</p>
9+
<p><strong>CAUTION:</strong> Make sure you are online before doing this, otherwise you won't be able to redownload the dictionary and you'll see an empty project until you can go online again.</p>
10+
<button
11+
class="btn btn-danger"
12+
style="cursor: pointer"
13+
type="button"
14+
data-ng-click="$ctrl.resetLocalStorage()"
15+
>
16+
Reset browser storage
17+
</button>
718
</div>
819
</div>

src/angular-app/languageforge/lexicon/settings/configuration/configuration-advanced-options.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import * as angular from 'angular';
22
import {LexiconConfig} from '../../shared/model/lexicon-config.model';
3+
import {CommentsOfflineCacheService} from '../../../../bellows/core/offline/comments-offline-cache.service';
4+
import {EditorOfflineCacheService} from '../../../../bellows/core/offline/editor-offline-cache.service';
35

46
export class AdvancedOptionsConfigurationController implements angular.IController {
57
accPollUpdateTimerSecondsDirty: number;
68
accOnUpdate: (params: { $event: { pollUpdateTimerSecondsDirty: number } }) => void;
79

8-
static $inject: string[] = ['$scope'];
9-
constructor(private $scope: angular.IScope) {
10+
static $inject: string[] = ['$scope', 'editorOfflineCache', 'commentsOfflineCache',];
11+
constructor(
12+
private $scope: angular.IScope,
13+
private editorOfflineCache: EditorOfflineCacheService,
14+
private commentsOfflineCache: CommentsOfflineCacheService,
15+
) {
1016
$scope.$watch(
1117
() => this.accPollUpdateTimerSecondsDirty,
1218
(newVal: number, oldVal: number) => {
@@ -18,6 +24,13 @@ export class AdvancedOptionsConfigurationController implements angular.IControll
1824
);
1925
}
2026

27+
async resetLocalStorage() {
28+
await this.editorOfflineCache.deleteAllEntries();
29+
await this.commentsOfflineCache.deleteAllComments();
30+
window.location.hash = '#!/';
31+
window.location.reload(); // To force the redownload
32+
}
33+
2134
$onChanges(changes: any) {
2235
const configChange = changes.accConfigPristine as angular.IChangesObject<LexiconConfig>;
2336
if (configChange != null && configChange.currentValue != null) {

0 commit comments

Comments
 (0)