diff --git a/config/environment.default.js b/config/environment.default.js
index 32edd1391d..42c3fc2452 100644
--- a/config/environment.default.js
+++ b/config/environment.default.js
@@ -24,7 +24,7 @@ module.exports = {
autoSync: {
defaultTime: 0,
maxBufferSize: 100,
- timePerMethod: {'Patch': 30} //time in seconds
+ timePerMethod: {'PATCH': 3} //time in seconds
}
},
// Form settings
diff --git a/src/app/+community-page/community-page.component.html b/src/app/+community-page/community-page.component.html
index 637e37af0c..ce86171370 100644
--- a/src/app/+community-page/community-page.component.html
+++ b/src/app/+community-page/community-page.component.html
@@ -24,9 +24,25 @@
[content]="communityPayload.copyrightText"
[hasInnerHtml]="true">
-
+
+
-
+
diff --git a/src/app/+community-page/community-page.component.ts b/src/app/+community-page/community-page.component.ts
index a6e1d5376c..5a36209c28 100644
--- a/src/app/+community-page/community-page.component.ts
+++ b/src/app/+community-page/community-page.component.ts
@@ -1,4 +1,4 @@
-import {mergeMap, filter, map} from 'rxjs/operators';
+import { mergeMap, filter, map, first, tap } from 'rxjs/operators';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@@ -24,6 +24,9 @@ import { hasValue } from '../shared/empty.util';
export class CommunityPageComponent implements OnInit, OnDestroy {
communityRD$: Observable>;
logoRD$: Observable>;
+ href: string;
+ newname: string;
+
private subs: Subscription[] = [];
constructor(
@@ -40,10 +43,20 @@ export class CommunityPageComponent implements OnInit, OnDestroy {
map((rd: RemoteData) => rd.payload),
filter((community: Community) => hasValue(community)),
mergeMap((community: Community) => community.logo));
+
+ this.communityRD$.pipe(first()).subscribe((crd) => {
+ this.href = crd.payload.self;
+ this.newname = crd.payload.name;
+ });
}
ngOnDestroy(): void {
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
}
+ patchIt(): void {
+ console.log('patching it!', this.href, this.newname);
+ this.communityDataService.patch(this.href, [{ op: 'replace', path: '/name', value: this.newname }]);
+ }
+
}
diff --git a/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.ts b/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.ts
index bb396a6692..fd14d6d3de 100644
--- a/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.ts
+++ b/src/app/+search-page/search-filters/search-filter/search-text-filter/search-text-filter.component.ts
@@ -1,6 +1,4 @@
-import { animate, state, style, transition, trigger } from '@angular/animations';
-import { Component, HostBinding, OnInit } from '@angular/core';
-import { Observable } from 'rxjs';
+import { Component, OnInit } from '@angular/core';
import { FilterType } from '../../../search-service/filter-type.model';
import {
facetLoad,
diff --git a/src/app/core/cache/object-cache.reducer.ts b/src/app/core/cache/object-cache.reducer.ts
index adea46bc57..f856b57892 100644
--- a/src/app/core/cache/object-cache.reducer.ts
+++ b/src/app/core/cache/object-cache.reducer.ts
@@ -182,8 +182,10 @@ function addPatchObjectCache(state: ObjectCacheState, action: AddPatchObjectCach
const newState = Object.assign({}, state);
if (hasValue(newState[uuid])) {
const patches = newState[uuid].patches;
- newState[uuid].patches = [...patches, {operations} as Patch];
- newState[uuid].isDirty = true;
+ newState[uuid] = Object.assign({}, newState[uuid], {
+ patches: [...patches, { operations } as Patch],
+ isDirty: true
+ });
}
return newState;
}
@@ -203,7 +205,7 @@ function applyPatchObjectCache(state: ObjectCacheState, action: ApplyPatchObject
const newState = Object.assign({}, state);
if (hasValue(newState[uuid])) {
// flatten two dimensional array
- const flatPatch: Operation[] = [].concat(...newState[uuid].patches);
+ const flatPatch: Operation[] = [].concat(...newState[uuid].patches.map((patch) => patch.operations));
const newData = applyPatch( newState[uuid].data, flatPatch);
newState[uuid].data = newData.newDocument;
newState[uuid].patches = [];
diff --git a/src/app/core/cache/object-cache.service.ts b/src/app/core/cache/object-cache.service.ts
index 5b0d818dd9..f60b2de684 100644
--- a/src/app/core/cache/object-cache.service.ts
+++ b/src/app/core/cache/object-cache.service.ts
@@ -91,7 +91,7 @@ export class ObjectCacheService {
getBySelfLink(selfLink: string): Observable {
return this.getEntry(selfLink).pipe(
map((entry: ObjectCacheEntry) => {
- const flatPatch: Operation[] = [].concat(...entry.patches);
+ const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
const patchedData = applyPatch(entry.data, flatPatch).newDocument;
return Object.assign({}, entry, { data: patchedData });
}
diff --git a/src/app/core/cache/server-sync-buffer.actions.ts b/src/app/core/cache/server-sync-buffer.actions.ts
index 2399db7c4d..69eb81b02f 100644
--- a/src/app/core/cache/server-sync-buffer.actions.ts
+++ b/src/app/core/cache/server-sync-buffer.actions.ts
@@ -31,7 +31,7 @@ export class AddToSSBAction implements Action {
* the unique href of the cached object entry that should be updated
*/
constructor(href: string, method: RestRequestMethod) {
- this.payload = { href, method: undefined };
+ this.payload = { href, method: method };
}
}
diff --git a/src/app/core/cache/server-sync-buffer.effects.ts b/src/app/core/cache/server-sync-buffer.effects.ts
index 8847b1d655..1211740ffe 100644
--- a/src/app/core/cache/server-sync-buffer.effects.ts
+++ b/src/app/core/cache/server-sync-buffer.effects.ts
@@ -1,4 +1,4 @@
-import { delay, exhaustMap, first, map, switchMap, tap } from 'rxjs/operators';
+import { delay, exhaustMap, first, map, startWith, switchMap, tap } from 'rxjs/operators';
import { Inject, Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import {
@@ -9,17 +9,17 @@ import {
} from './server-sync-buffer.actions';
import { GLOBAL_CONFIG } from '../../../config';
import { GlobalConfig } from '../../../config/global-config.interface';
-import { CoreState } from '../core.reducers';
-import { Action, select, Store } from '@ngrx/store';
+import { coreSelector, CoreState } from '../core.reducers';
+import { Action, createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
import { ServerSyncBufferEntry, ServerSyncBufferState } from './server-sync-buffer.reducer';
-import { of as observableOf, combineLatest as observableCombineLatest } from 'rxjs';
+import { of as observableOf, combineLatest as observableCombineLatest, empty as observableEmpty } from 'rxjs';
import { RequestService } from '../data/request.service';
import { PutRequest } from '../data/request.models';
import { ObjectCacheService } from './object-cache.service';
import { ApplyPatchObjectCacheAction } from './object-cache.actions';
import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer';
import { GenericConstructor } from '../shared/generic-constructor';
-import { hasValue } from '../../shared/empty.util';
+import { hasValue, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
import { Observable } from 'rxjs/internal/Observable';
import { RestRequestMethod } from '../data/rest-request-method';
@@ -29,9 +29,8 @@ export class ServerSyncBufferEffects {
.pipe(
ofType(ServerSyncBufferActionTypes.ADD),
exhaustMap((action: AddToSSBAction) => {
- // const autoSyncConfig = this.EnvConfig.cache.autoSync;
- // const timeoutInSeconds = autoSyncConfig.timePerMethod[action.type] || autoSyncConfig.defaultTime;
- const timeoutInSeconds = 0;
+ const autoSyncConfig = this.EnvConfig.cache.autoSync;
+ const timeoutInSeconds = autoSyncConfig.timePerMethod[action.payload.method] || autoSyncConfig.defaultTime;
return observableOf(new CommitSSBAction(action.payload.method)).pipe(delay(timeoutInSeconds * 1000))
})
);
@@ -41,7 +40,7 @@ export class ServerSyncBufferEffects {
ofType(ServerSyncBufferActionTypes.COMMIT),
switchMap((action: CommitSSBAction) => {
return this.store.pipe(
- select(serverSyncBufferSelector),
+ select(serverSyncBufferSelector()),
map((bufferState: ServerSyncBufferState) => {
const actions: Array> = bufferState.buffer
.filter((entry: ServerSyncBufferEntry) => {
@@ -54,29 +53,41 @@ export class ServerSyncBufferEffects {
})
.map((entry: ServerSyncBufferEntry) => {
if (entry.method === RestRequestMethod.PATCH) {
+ console.log(this.applyPatch(entry.href));
return this.applyPatch(entry.href);
} else {
/* TODO other request stuff */
}
});
+ console.log(actions);
/* Add extra action to array, to make sure the ServerSyncBuffer is emptied afterwards */
- return observableCombineLatest(actions).pipe(
- map((array) => array.push(new EmptySSBAction(action.payload)))
- );
+ if (isNotEmpty(actions) && isNotUndefined(actions[0])) {
+ return observableCombineLatest(...actions).pipe(
+ map((array) => {
+ console.log(array);
+ return array.push(new EmptySSBAction(action.payload));
+ })
+ );
+ } else {
+ return { type:'NO_ACTION' };
+ }
})
)
})
);
+
private applyPatch(href: string): Observable {
const patchObject = this.objectCache.getBySelfLink(href);
- return patchObject.pipe(
+ const test = patchObject.pipe(
map((object) => {
const serializedObject = new DSpaceRESTv2Serializer(object.constructor as GenericConstructor<{}>).serialize(object);
this.requestService.configure(new PutRequest(this.requestService.generateRequestId(), href, serializedObject));
+ console.log(new ApplyPatchObjectCacheAction(href));
return new ApplyPatchObjectCacheAction(href)
})
)
+ return test;
}
constructor(private actions$: Actions,
@@ -88,4 +99,6 @@ export class ServerSyncBufferEffects {
}
}
-export const serverSyncBufferSelector = (state: CoreState) => state['cache/syncbuffer'];
+export function serverSyncBufferSelector(): MemoizedSelector {
+ return createSelector(coreSelector, (state: CoreState) => state['cache/syncbuffer']);
+}
diff --git a/src/config/cache-config.interface.ts b/src/config/cache-config.interface.ts
index b8651ed107..3e9334e300 100644
--- a/src/config/cache-config.interface.ts
+++ b/src/config/cache-config.interface.ts
@@ -4,5 +4,5 @@ import { AutoSyncConfig } from './auto-sync-config.interface';
export interface CacheConfig extends Config {
msToLive: number,
control: string,
- // autoSync: AutoSyncConfig
+ autoSync: AutoSyncConfig
}