Repository navigation
Implement auto-recover functionality [B: 1403] #483
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ec64c0b
Reset and rerun of commit
droberts-ctrlo 39498e3
Unit test failure fix
droberts-ctrlo de0bcfd
JSTree and Test fixes
droberts-ctrlo ef3db97
Fix for textarea not setting values correctly
droberts-ctrlo f31e3f6
Fix for set-field-values not working with different date formats
droberts-ctrlo d0f0de6
Updated storage to ignore empty values
droberts-ctrlo 12c606a
Merge branch 'dev' into autosave-reset
droberts-ctrlo d852b03
Styling and error handling
droberts-ctrlo fba4f8a
Set max height of modal
droberts-ctrlo e7ab764
Added overflow to modal
droberts-ctrlo a227963
Update setdate
droberts-ctrlo 68fc58b
Updated to *remove* clone and allow empty values to be saved
droberts-ctrlo 25dea35
Updated for better erroring of curvals
droberts-ctrlo 70a447d
Update to erroring
droberts-ctrlo 041ba36
Fix for error not displaying correctly in curvals
droberts-ctrlo 73fd8a5
Clearer feedback
droberts-ctrlo a13063b
Moved `get_key` into API route
droberts-ctrlo 10f3ea0
Updated code to call correct endpoint for key
droberts-ctrlo d649a50
Updated for clearer feedback on curvals
droberts-ctrlo 48b7d9b
Forgot feedback for successful validation
droberts-ctrlo 906c5d8
Updated to allow for better error handling
droberts-ctrlo ac6e033
Updated node tests
droberts-ctrlo b5579e4
Updated GADSStorage tests as they are incompatible with Node 16
droberts-ctrlo 2b85d32
Added basic JSDoc to `GadsStorage`
droberts-ctrlo d21d155
Fixed autorecover (#27)
droberts-ctrlo 73c1c88
Removed error in restore
droberts-ctrlo c9f845b
Re-added error handling using different method
droberts-ctrlo 4f101b5
Removed import for testing definitions
droberts-ctrlo 9cd46bb
Disable writing to restore values during recovery
droberts-ctrlo 7ac8772
Removed erroneous clone behaviour
droberts-ctrlo 06baf02
Fix to recovery overwrites
droberts-ctrlo 1f261a5
Removed test condition in GadsStorage
droberts-ctrlo 33e3896
Fixed wording
droberts-ctrlo 9ffb2ee
Fixed wording
droberts-ctrlo 149f570
Modified code as suggested
droberts-ctrlo 5c0b51f
Updated from parameter to clone_from
droberts-ctrlo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { clearSavedFormValues } from "./common"; | ||
|
|
||
| export default function createCancelButton(el: HTMLElement | JQuery<HTMLElement>) { | ||
| const $el = $(el); | ||
| if ($el[0].tagName !== 'BUTTON') return; | ||
| $el.data('cancel-button', "true"); | ||
| $el.on('click', async () => { | ||
| const href = $el.data('href'); | ||
| await clearSavedFormValues($el.closest('form')); | ||
| if (href) | ||
|
droberts-ctrlo marked this conversation as resolved.
Resolved
|
||
| window.location.href = href; | ||
| else | ||
| window.history.back(); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import "../../../testing/globals.definitions"; | ||
| import {layoutId, recordId, table_key} from "./common"; | ||
|
|
||
| describe("Common button tests",()=>{ | ||
| it("should populate table_key",()=>{ | ||
| expect(table_key()).toBe("linkspace-record-change-undefined-0"); // Undefined because $('body').data('layout-identifier') is not defined | ||
| }); | ||
|
|
||
| it("should have a layoutId", ()=>{ | ||
| $('body').data('layout-identifier', 'layoutId'); | ||
| expect(layoutId()).toBe('layoutId'); | ||
| }); | ||
|
|
||
| it("should have a recordId", ()=>{ | ||
| expect(isNaN(parseInt(location.pathname.split('/').pop() ?? ""))).toBe(true); | ||
| expect(recordId()).toBe(0); | ||
| }); | ||
|
|
||
| it("should populate table_key fully",()=>{ | ||
| $('body').data('layout-identifier', 'layoutId'); | ||
| expect(table_key()).toBe("linkspace-record-change-layoutId-0"); | ||
| }); | ||
| }); |
|
droberts-ctrlo marked this conversation as resolved.
Resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import gadsStorage from "util/gadsStorage"; | ||
|
|
||
| /** | ||
| * Clear all saved form values for the current record | ||
| * @param $form The form to clear the data for | ||
| */ | ||
| export async function clearSavedFormValues($form: JQuery<HTMLElement>) { | ||
|
droberts-ctrlo marked this conversation as resolved.
Resolved
|
||
| if (!$form || $form.length === 0) return; | ||
| const layout = layoutId(); | ||
| const record = recordId(); | ||
| const ls = storage(); | ||
| const item = await ls.getItem(table_key()); | ||
|
|
||
| if (item) ls.removeItem(`linkspace-record-change-${layout}-${record}`); | ||
| await Promise.all($form.find(".linkspace-field").map(async (_, el) => { | ||
| const field_id = $(el).data("column-id"); | ||
| const item = await gadsStorage.getItem(`linkspace-column-${field_id}-${layout}-${record}`); | ||
| if (item) gadsStorage.removeItem(`linkspace-column-${field_id}-${layout}-${record}`); | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Get the layout identifier from the body data | ||
| * @returns The layout identifier | ||
| */ | ||
| export function layoutId() { | ||
| return $('body').data('layout-identifier'); | ||
| } | ||
|
|
||
| /** | ||
| * Get the record identifier from the body data | ||
| * @returns The record identifier | ||
| */ | ||
| export function recordId() { | ||
| return $('body').find('.form-edit').data('current-id') || 0; | ||
| } | ||
|
|
||
| /** | ||
| * Get the key for the table used for saving form values | ||
| * @returns The key for the table | ||
| */ | ||
| export function table_key() { | ||
| return `linkspace-record-change-${layoutId()}-${recordId()}`; | ||
| } | ||
|
|
||
| /** | ||
| * Get the storage object - this originally was used in debugging to allow for the storage object to be mocked | ||
| * @returns The storage object | ||
| */ | ||
| export function storage() { | ||
| return gadsStorage; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
src/frontend/components/button/lib/submit-draft-record-button.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| import { clearSavedFormValues } from "./common"; | ||
|
|
||
| /** | ||
| * Create a submit draft record button | ||
| * @param element {JQuery<HTMLElement>} The button element | ||
| */ | ||
| export default function createSubmitDraftRecordButton(element: JQuery<HTMLElement>) { | ||
| element.on("click", (ev: JQuery.ClickEvent) => { | ||
| element.on("click", async (ev: JQuery.ClickEvent) => { | ||
| const $button = $(ev.target).closest('button'); | ||
| const $form = $button.closest("form"); | ||
|
|
||
| // Remove the required attribute from hidden required dependent fields | ||
| $form.find(".form-group *[aria-required]").removeAttr('required'); | ||
| // As the draft should save all changed values, we clear them from the local storage | ||
| await clearSavedFormValues(ev.target.closest("form")); | ||
|
droberts-ctrlo marked this conversation as resolved.
Resolved
|
||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/frontend/components/form-group/autosave/_autosave.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| .field--changed { | ||
| input, .jstree-container-ul, .form-control { | ||
| background-color: $field-highlight; | ||
| border-radius: $input-border-radius; | ||
| } | ||
| } | ||
|
|
||
| .modal-autosave { | ||
| max-height: 20rem; | ||
| overflow-y: auto; | ||
| overflow-x: hidden; | ||
| } | ||
|
|
||
| li.li-success { | ||
| list-style: none; | ||
| &::before { | ||
| content: '\2713'; | ||
| color: green; | ||
| font-size: 1.5em; | ||
| margin-right: 0.5em; | ||
| } | ||
| } | ||
|
|
||
| li.li-error { | ||
| list-style: none; | ||
| &::before { | ||
| content: '\2717'; | ||
| color: red; | ||
| font-size: 1.5em; | ||
| margin-right: 0.5em; | ||
| } | ||
| } |
|
droberts-ctrlo marked this conversation as resolved.
Resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { initializeComponent } from 'component'; | ||
| import AutosaveComponent from './lib/component'; | ||
| import AutosaveModal from './lib/modal'; | ||
| import gadsStorage from 'util/gadsStorage'; | ||
|
|
||
| export default (scope) => { | ||
| if (gadsStorage.enabled) { | ||
| try { | ||
| initializeComponent(scope, '.linkspace-field', AutosaveComponent); | ||
| initializeComponent(scope, '#restoreValuesModal', AutosaveModal); | ||
| } catch(e) { | ||
| console.error(e); | ||
| $('.content-block__main-content').prepend('<div class="alert alert-danger">Auto-recover failed to initialize. ' + e.message ? e.message : e + '</div>'); | ||
| } | ||
| } else { | ||
| $('.content-block__main-content').prepend('<div class="alert alert-warning">Auto-recover is disabled as your browser does not support encryption</div>'); | ||
| } | ||
| }; |
38 changes: 38 additions & 0 deletions
38
src/frontend/components/form-group/autosave/lib/autosave.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import "../../../../testing/globals.definitions"; | ||
| import AutosaveBase from './autosaveBase'; | ||
|
|
||
| class TestAutosave extends AutosaveBase { | ||
| initAutosave(): void { | ||
| console.log('initAutosave'); | ||
| } | ||
| } | ||
|
|
||
| describe('AutosaveBase', () => { | ||
| beforeAll(() => { | ||
| document.body.innerHTML = ` | ||
| <body> | ||
| <div id="test"></div> | ||
| </body> | ||
| `; | ||
| $('body').data('layout-identifier', 1); | ||
| }); | ||
|
|
||
| afterAll(()=>{ | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('should return layoutId', () => { | ||
| const autosave = new TestAutosave(document.getElementById('test')!); | ||
| expect(autosave.layoutId).toBe(1); | ||
| }); | ||
|
|
||
| it('should return recordId', () => { | ||
| const autosave = new TestAutosave(document.getElementById('test')!); | ||
| expect(autosave.recordId).toBe(0); | ||
| }); | ||
|
|
||
| it('should return table_key', () => { | ||
| const autosave = new TestAutosave(document.getElementById('test')!); | ||
| expect(autosave.table_key).toBe('linkspace-record-change-1-0'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.