Browse Source

Unsubscription.

pull/65/merge
Sebastian Stehle 9 years ago
parent
commit
a576a1f083
  1. 20
      src/Squidex/app/features/content/pages/contents/contents-page.component.ts
  2. 48
      src/Squidex/app/framework/angular/date-time-editor.component.ts

20
src/Squidex/app/features/content/pages/contents/contents-page.component.ts

@ -177,16 +177,16 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy
public load(showInfo = false) { public load(showInfo = false) {
this.appNameOnce() this.appNameOnce()
.switchMap(app => this.contentsService.getContents(app, this.schema.name, this.contentsPager.pageSize, this.contentsPager.skip, this.contentsQuery)) .switchMap(app => this.contentsService.getContents(app, this.schema.name, this.contentsPager.pageSize, this.contentsPager.skip, this.contentsQuery))
.subscribe(dtos => { .subscribe(dtos => {
this.contentItems = ImmutableArray.of(dtos.items); this.contentItems = ImmutableArray.of(dtos.items);
this.contentsPager = this.contentsPager.setCount(dtos.total); this.contentsPager = this.contentsPager.setCount(dtos.total);
if (showInfo) { if (showInfo) {
this.notifyInfo('Contents reloaded.'); this.notifyInfo('Contents reloaded.');
} }
}, error => { }, error => {
this.notifyError(error); this.notifyError(error);
}); });
} }
public dropData(content: ContentDto) { public dropData(content: ContentDto) {

48
src/Squidex/app/framework/angular/date-time-editor.component.ts

@ -5,8 +5,9 @@
* Copyright (c) Sebastian Stehle. All rights reserved * Copyright (c) Sebastian Stehle. All rights reserved
*/ */
import { AfterViewInit, Component, forwardRef, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; import { AfterViewInit, Component, forwardRef, ElementRef, Input, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Subscription } from 'rxjs';
import * as moment from 'moment'; import * as moment from 'moment';
let Pikaday = require('pikaday/pikaday'); let Pikaday = require('pikaday/pikaday');
@ -23,7 +24,9 @@ export const SQX_DATE_TIME_EDITOR_CONTROL_VALUE_ACCESSOR: any = {
templateUrl: './date-time-editor.component.html', templateUrl: './date-time-editor.component.html',
providers: [SQX_DATE_TIME_EDITOR_CONTROL_VALUE_ACCESSOR] providers: [SQX_DATE_TIME_EDITOR_CONTROL_VALUE_ACCESSOR]
}) })
export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, AfterViewInit { export class DateTimeEditorComponent implements ControlValueAccessor, OnDestroy, OnInit, AfterViewInit {
private timeSubscription: Subscription;
private dateSubscription: Subscription;
private picker: any; private picker: any;
private timeValue: any | null = null; private timeValue: any | null = null;
private dateValue: any | null = null; private dateValue: any | null = null;
@ -54,26 +57,33 @@ export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, Af
public isDisabled = false; public isDisabled = false;
public ngOnInit() { public ngOnDestroy() {
this.timeControl.valueChanges.subscribe(value => { this.dateSubscription.unsubscribe();
if (!value || value.length === 0) { this.timeSubscription.unsubscribe();
this.timeValue = null; }
} else {
this.timeValue = moment(value, 'HH:mm:ss');
}
this.updateValue(); public ngOnInit() {
}); this.timeSubscription =
this.timeControl.valueChanges.subscribe(value => {
if (!value || value.length === 0) {
this.timeValue = null;
} else {
this.timeValue = moment(value, 'HH:mm:ss');
}
this.dateControl.valueChanges.subscribe(value => { this.updateValue();
if (!value || value.length === 0) { });
this.dateValue = null;
} else { this.dateSubscription =
this.dateValue = moment(value, 'YYYY-MM-DD'); this.dateControl.valueChanges.subscribe(value => {
} if (!value || value.length === 0) {
this.dateValue = null;
} else {
this.dateValue = moment(value, 'YYYY-MM-DD');
}
this.updateValue(); this.updateValue();
}); });
} }
public writeValue(value: any) { public writeValue(value: any) {

Loading…
Cancel
Save