Skip to content

Commit a7c51b3

Browse files
author
Mirek Simek
committed
version 6.1.2: Added ANGULAR_FORM_ABSOLUTE_URLS django settings for cases where django server and angular are on different hosts/ports (CORS), added valueChanged emitter to in-page dialogs
1 parent daa4695 commit a7c51b3

File tree

11 files changed

+55
-8
lines changed

11 files changed

+55
-8
lines changed

angular_dynamic_forms/rest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66

7+
from django.conf import settings
78
from django.core.exceptions import FieldDoesNotExist
89
from django.db.models import TextField
910
from django.http import Http404
@@ -323,7 +324,11 @@ def _get_form_metadata(self, has_instance, form_name='', base_path=None):
323324

324325
ret['method'] = 'patch' if has_instance else 'post'
325326
ret['hasInitialData'] = has_instance
326-
ret['djangoUrl'] = base_path + self._get_url_by_form_id(form_name)
327+
328+
if getattr(settings, 'ANGULAR_FORM_ABSOLUTE_URLS', False):
329+
ret['djangoUrl'] = self.request.build_absolute_uri(base_path + self._get_url_by_form_id(form_name))
330+
else:
331+
ret['djangoUrl'] = base_path + self._get_url_by_form_id(form_name)
327332

328333
# print(json.dumps(ret, indent=4))
329334
return ret

demo/django/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Versions should comply with PEP440. For a discussion on single-sourcing
2626
# the version across setup.py and the project code, see
2727
# https://packaging.python.org/en/latest/single_source_version.html
28-
version='6.1.1',
28+
version='6.1.2',
2929

3030
description='Angular forms for django rest framework',
3131
long_description=long_description,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-demo",
3-
"version": "6.1.1",
3+
"version": "6.1.2",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve --proxy-config proxy.conf.json",

projects/django-angular-dynamic-forms/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "django-angular-dynamic-forms",
3-
"version": "6.1.1",
3+
"version": "6.1.2",
44
"license": "MIT",
55
"description": "Django Rest Framework meets Angular 5 material.io dynamic forms - rapid development of create and edit dialogs",
66
"keywords": [],

projects/django-angular-dynamic-forms/src/impl/dialog-django-form.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<h1 mat-dialog-title *ngIf="config.formTitle">{{ config.formTitle }}</h1>
55
<div mat-dialog-content>
66
<django-form-content [layout]="config.layout" [initialData]="config.initialData" [errors]="errors$|async"
7-
(submit)="submitted(undefined, undefined)" #form>
7+
(submit)="submitted(undefined, undefined)"
8+
#form>
89
</django-form-content>
910
</div>
1011

projects/django-angular-dynamic-forms/src/impl/django-form-base.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export class DjangoFormBaseComponent implements OnInit {
4242
@Input()
4343
public extraConfig: any = {};
4444

45+
@Output()
46+
valueChanged = new EventEmitter<any>();
47+
4548
@ViewChild('form')
4649
protected form: DjangoFormContentComponent;
4750

projects/django-angular-dynamic-forms/src/impl/django-form-content.component.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {
6969
} from '../foreign';
7070
import {MatDialog} from '@angular/material';
7171
import {catchError} from 'rxjs/operators';
72+
import {Subscription} from 'rxjs';
7273

7374

7475
class AutoCompleter {
@@ -138,6 +139,10 @@ export class DjangoFormContentComponent implements OnInit, OnDestroy {
138139
private foreigns: any[] = [];
139140
private foreignDefinitions: { [s: string]: any; } = {};
140141

142+
@Output()
143+
valueChanged = new EventEmitter<any>();
144+
valueChangedSubscription: Subscription;
145+
141146
@Input()
142147
public set layout(_layout: FieldConfig[]) {
143148
if (_layout) {
@@ -215,6 +220,9 @@ export class DjangoFormContentComponent implements OnInit, OnDestroy {
215220

216221
public ngOnDestroy() {
217222
this._unbindForeignKey();
223+
if (this.valueChangedSubscription) {
224+
this.valueChangedSubscription.unsubscribe();
225+
}
218226
}
219227

220228
public get valid() {
@@ -240,6 +248,25 @@ export class DjangoFormContentComponent implements OnInit, OnDestroy {
240248
this._bindAutocomplete();
241249
this._bindForeignKey();
242250
this._updateInitialData();
251+
if (this.valueChangedSubscription) {
252+
this.valueChangedSubscription.unsubscribe();
253+
}
254+
this.valueChangedSubscription = this.formGroup.valueChanges.subscribe(value => {
255+
function _flatten(o) {
256+
if (o === undefined || o === null) {
257+
return [];
258+
}
259+
return [].concat(...Object.keys(o)
260+
.map(k =>
261+
typeof o[k] === 'object' ?
262+
_flatten(o[k]) :
263+
({[k]: o[k]})
264+
)
265+
);
266+
}
267+
value = Object.assign({}, ..._flatten(value));
268+
this.valueChanged.emit(value);
269+
});
243270
}
244271

245272
private _bindAutocomplete() {

projects/django-angular-dynamic-forms/src/impl/inpage-django-form.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<ng-container *ngIf="config$|async; let config">
33

44
<django-form-content [layout]="config.layout" [initialData]="config.initialData" [errors]="errors$|async"
5-
(submit)="submitted(undefined, undefined)" #form>
5+
(submit)="submitted(undefined, undefined)"
6+
(valueChanged)="onModified($event)"
7+
#form>
68
</django-form-content>
79

810
<div *ngIf="config.actions" fxLayout="row" class="dadf-buttons">

projects/django-angular-dynamic-forms/src/impl/inpage-django-form.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ export class InPageDjangoFormComponent extends DjangoFormBaseComponent {
2323
this.shown.emit({form: this, config: config});
2424
}
2525
}
26+
27+
onModified(data: any) {
28+
this.valueChanged.emit(data);
29+
}
2630
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Versions should comply with PEP440. For a discussion on single-sourcing
2626
# the version across setup.py and the project code, see
2727
# https://packaging.python.org/en/latest/single_source_version.html
28-
version='6.1.1',
28+
version='6.1.2',
2929

3030
description='Django Rest Framework meets Angular 5 material.io dynamic forms - rapid development of create and edit dialogs',
3131
long_description=long_description,

0 commit comments

Comments
 (0)