-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #957 from geonetwork/DH/open-data-switch
[Editor]: Add an open data switch
- Loading branch information
Showing
18 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
6 changes: 6 additions & 0 deletions
6
...omponents/record-form/form-field/form-field-open-data/form-field-open-data.component.html
This file contains 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,6 @@ | ||
<gn-ui-check-toggle | ||
[label]="'editor.record.form.classification.opendata' | translate" | ||
[value]="value" | ||
(toggled)="onOpenDataToggled($event)" | ||
data-cy="openDataToggle" | ||
></gn-ui-check-toggle> |
47 changes: 47 additions & 0 deletions
47
...onents/record-form/form-field/form-field-open-data/form-field-open-data.component.spec.ts
This file contains 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,47 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { FormFieldOpenDataComponent } from './form-field-open-data.component' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
import { FormControl } from '@angular/forms' | ||
|
||
jest.mock('./../../../../fields.config', () => { | ||
return { | ||
OPEN_DATA_LICENSES: ['CC-BY'], | ||
} | ||
}) | ||
|
||
describe('FormFieldOpenDataComponent', () => { | ||
let component: FormFieldOpenDataComponent | ||
let fixture: ComponentFixture<FormFieldOpenDataComponent> | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [FormFieldOpenDataComponent, TranslateModule.forRoot()], | ||
}).compileComponents() | ||
|
||
fixture = TestBed.createComponent(FormFieldOpenDataComponent) | ||
component = fixture.componentInstance | ||
component.control = new FormControl() | ||
component.control.setValue([{ text: 'odc-by' }]) | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should emit the new license value on toggle', () => { | ||
const control = new FormControl() | ||
const setValueSpy = jest.spyOn(control, 'setValue') | ||
component.control = control | ||
|
||
component.onOpenDataToggled(true) | ||
|
||
expect(setValueSpy).toHaveBeenCalledWith([{ text: 'CC-BY' }]) | ||
}) | ||
|
||
it('should emit the event value on toggle', () => { | ||
const toggledSpy = jest.spyOn(component.visibilityChange, 'emit') | ||
component.onOpenDataToggled(true) | ||
expect(toggledSpy).toHaveBeenCalledWith(true) | ||
}) | ||
}) |
59 changes: 59 additions & 0 deletions
59
.../components/record-form/form-field/form-field-open-data/form-field-open-data.component.ts
This file contains 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,59 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
EventEmitter, | ||
Input, | ||
OnChanges, | ||
OnInit, | ||
Output, | ||
SimpleChanges, | ||
} from '@angular/core' | ||
import { FormControl } from '@angular/forms' | ||
import { CheckToggleComponent } from '@geonetwork-ui/ui/inputs' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
import { OPEN_DATA_LICENSES } from './../../../../fields.config' | ||
import { Subscription } from 'rxjs' | ||
|
||
@Component({ | ||
selector: 'gn-ui-form-field-open-data', | ||
templateUrl: './form-field-open-data.component.html', | ||
styleUrls: ['./form-field-open-data.component.css'], | ||
standalone: true, | ||
imports: [CheckToggleComponent, TranslateModule], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class FormFieldOpenDataComponent implements OnInit { | ||
@Input() control: FormControl | ||
value = false | ||
@Output() visibilityChange = new EventEmitter<boolean>() | ||
subscription: Subscription | ||
|
||
get config() { | ||
return OPEN_DATA_LICENSES | ||
} | ||
|
||
ngOnInit() { | ||
this.initToggle() | ||
this.subscription = new Subscription() | ||
|
||
this.subscription.add( | ||
this.control.valueChanges.subscribe((value) => { | ||
this.value = this.config.includes(value[0].text) | ||
this.visibilityChange.emit(this.value) | ||
}) | ||
) | ||
} | ||
|
||
initToggle() { | ||
this.value = this.config.includes(this.control.value[0].text) | ||
this.visibilityChange.emit(this.value) | ||
} | ||
|
||
onOpenDataToggled(boolean) { | ||
if (boolean) { | ||
this.control.setValue([{ text: this.config[0] }]) | ||
} | ||
this.value = !this.value | ||
this.visibilityChange.emit(boolean) | ||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.html
This file contains 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 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 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 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
Binary file not shown.
This file contains 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 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 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 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 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 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 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 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