Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gallayl committed Dec 5, 2017
2 parents cc0e523 + 5dad806 commit 33a4f23
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sn-client-js",
"version": "3.0.0",
"version": "3.0.1",
"description": "A JavaScript client for Sense/Net ECM that makes it easy to use the REST API of the Content Repository.",
"main": "dist/src/SN.js",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions src/Authentication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @module Authentication
* @preferred
* @description This module that contains authentication-related classes, types and interfaces
*
* <p data-height="268" data-theme-id="light" data-slug-hash="qPjmdj" data-default-tab="result" data-user="gallayl" data-embed-version="2" data-pen-title="@sensenet/sn-client-js/login" class="codepen">See the Pen <a href="https://codepen.io/gallayl/pen/qPjmdj/">@sensenet/sn-client-js/login</a> by gallayl (<a href="https://codepen.io/gallayl">@gallayl</a>) on <a href="https://codepen.io">CodePen</a>.</p> <script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
*/ /** */

export * from './IAuthenticationService';
Expand Down
14 changes: 10 additions & 4 deletions src/Content/ContentInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
referenceSettings.forEach((f) => {

if (!this._fieldHandlerCache[f.Name]) {
this._fieldHandlerCache[f.Name] = f.AllowMultiple ? new ContentListReferenceField(this[f.Name], f, this._repository) : new ContentReferenceField(this[f.Name], f, this._repository);
this._fieldHandlerCache[f.Name] = f.AllowMultiple ? new ContentListReferenceField(this[f.Name], f, this, this._repository) : new ContentReferenceField(this[f.Name], f, this, this._repository);
} else {
this._fieldHandlerCache[f.Name].HandleLoaded(this[f.Name]);
}
Expand All @@ -187,7 +187,7 @@
if (isSavedContent<T>(this)) {
return this as SavedContent<T>;
}
throw new Error('Contnet is not saved.');
throw new Error('Content is not saved.');
}

/**
Expand Down Expand Up @@ -467,14 +467,20 @@
* @param {string} scenario
* @returns {Observable<ActionModel[]>} Returns an RxJS observable that you can subscribe of in your code.
* ```
* content.Actions('ListItem')
* content.GetActions('ListItem')
* .subscribe(response => {
* console.log(response);
* },
* error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value));
* ```
*/
public Actions(scenario?: string): Observable<ActionModel[]> {
public Actions(scenario?: string): Observable<ActionModel[]> {
// tslint:disable-next-line:no-console
console.warn(`Method 'content.Action() is deprecated' and will be removed. Please use content.GetActions() instead`);
return this.GetActions(scenario);
}

public GetActions(scenario?: string): Observable<ActionModel[]> {
return this._odata.Get({
path: ODataHelper.joinPaths(this.GetFullPath(), 'Actions'),
params: {
Expand Down
5 changes: 3 additions & 2 deletions src/Content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* @module Content
* @preferred
*
* @description Top level base type of sense NET's Type hierarchy.
*
* @description Top level base type of sense NET's Type hierarchy. Content has the basic properties and functionality that can be reached on all of the inherited types. It's almost the same as an abstract class, it may not be instantiated directly,
* but it has the basic methods implemented that can be called on obejcts with derived types. Unlike other Content Types it is not autogenerated.
* Content has the basic properties and functionality that can be reached on all of the inherited types. It's almost the same as an abstract class, it may not be instantiated directly,
* but it has the basic methods implemented that can be called on obejcts with derived types.
* <p data-height="314" data-theme-id="light" data-slug-hash="QqgvKL" data-default-tab="result" data-user="gallayl" data-embed-version="2" data-pen-title="@sensenet/sn-client-js/content" class="codepen">See the Pen <a href="https://codepen.io/gallayl/pen/QqgvKL/">@sensenet/sn-client-js/content</a> by gallayl (<a href="https://codepen.io/gallayl">@gallayl</a>) on <a href="https://codepen.io">CodePen</a>.</p><script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
*
* Unlike other Content Types it is not autogenerated.
*
Expand Down
14 changes: 10 additions & 4 deletions src/ContentReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DeferredObject } from './ComplexTypes';
import { IContent, isDeferred, isIContent, SavedContent } from './Content';
import { ReferenceFieldSetting } from './FieldSettings';
import { IODataParams } from './ODataApi/ODataParams';
import { joinPaths } from './ODataHelper';
import { FinializedQuery } from './Query';
import { BaseRepository } from './Repository/BaseRepository';
import { ContentTypes, isIContentList } from './SN';
Expand Down Expand Up @@ -101,10 +102,12 @@ export class ContentReferenceField<T extends IContent> extends ReferenceAbstract
* @returns {Observable<T>} An observable that will publish the referenced content
*/
public GetContent(odataOptions?: IODataParams<T>): Observable<SavedContent<T>> {
if (this._contentReference !== undefined) {
if (!this._ownerContent.IsSaved || this._contentReference !== undefined) {
return Observable.of(this._contentReference);
}
const request = this.Repository.GetODataApi().Get({ path: this._referenceUrl, params: odataOptions })
const request = this.Repository.GetODataApi().Get({
path: this._referenceUrl || joinPaths(this._ownerContent.GetFullPath(), this.FieldSetting.Name),
params: odataOptions })
.map((r) => {
return r && r.d && this.Repository.HandleLoadedContent<T>(r.d);
}).share();
Expand Down Expand Up @@ -137,6 +140,7 @@ export class ContentReferenceField<T extends IContent> extends ReferenceAbstract

constructor(fieldData: DeferredObject | SavedContent<T>,
public readonly FieldSetting: ReferenceFieldSetting,
private readonly _ownerContent: SavedContent,
public readonly Repository: BaseRepository) {
super();
this.HandleLoaded(fieldData);
Expand Down Expand Up @@ -174,12 +178,12 @@ export class ContentListReferenceField<T extends IContent> extends ReferenceAbst
* @returns {Observable<T[]>} An observable that will publish the list of the referenced content
*/
public GetContent(odataOptions?: IODataParams<T>): Observable<SavedContent<T>[]> {
if (this._contentReferences) {
if (!this._ownerContent.IsSaved || this._contentReferences) {
return Observable.of(this._contentReferences);
}
//
const request = this.Repository.GetODataApi().Fetch<T>({
path: this._referenceUrl,
path: this._referenceUrl || joinPaths(this._ownerContent.GetFullPath(), this.FieldSetting.Name),
params: odataOptions
}).map((resp) => {
return resp && resp.d && resp.d.results.map((c) => this.Repository.HandleLoadedContent<T>(c)) || [];
Expand Down Expand Up @@ -217,6 +221,8 @@ export class ContentListReferenceField<T extends IContent> extends ReferenceAbst

constructor(fieldData: DeferredObject | T[],
public readonly FieldSetting: ReferenceFieldSetting,
private readonly _ownerContent: SavedContent,

public readonly Repository: BaseRepository) {
super();
this.HandleLoaded(fieldData);
Expand Down
2 changes: 2 additions & 0 deletions src/Query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @preferred
*
* @description Classes and Methods for creating, manipulating and executing content queries in sensenet ECM.
*
* <p data-height="339" data-theme-id="light" data-slug-hash="xXrLXw" data-default-tab="js,result" data-user="gallayl" data-embed-version="2" data-pen-title="@sensenet/sn-client-js/query" class="codepen">See the Pen <a href="https://codepen.io/gallayl/pen/xXrLXw/">@sensenet/sn-client-js/query</a> by gallayl (<a href="https://codepen.io/gallayl">@gallayl</a>) on <a href="https://codepen.io">CodePen</a>.</p><script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
*/ /** */

export * from './Query';
Expand Down
7 changes: 5 additions & 2 deletions test/ContentListReferenceFieldTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ export class ContentListReferenceFieldTests {
private _unloadedRef: ContentListReferenceField<Task>;
private _loadedRef: ContentListReferenceField<Task>;

private _ownerContent: Task;

private _repo: MockRepository;
// tslint:disable-next-line:naming-convention
public before() {
this._repo = new MockRepository();
this._ownerContent = this._repo.HandleLoadedContent({Id: 123765, Path: 'Root/Tests', Name: 'TestOwnerContent'}, Task);
this._repo.Authentication.StateSubject.next(LoginState.Authenticated);
this._loadedRef = new ContentListReferenceField(
[{
Expand All @@ -29,12 +32,12 @@ export class ContentListReferenceFieldTests {
Name: 'Name',
Type: 'Task',
DueText: 'testDueText'
} as Task], {} as ReferenceFieldSetting, this._repo);
} as Task], {} as ReferenceFieldSetting, this._ownerContent, this._repo);
this._unloadedRef = new ContentListReferenceField({
__deferred: {
uri: 'a/b/c'
}
} as DeferredObject, {} as ReferenceFieldSetting, this._repo);
} as DeferredObject, {} as ReferenceFieldSetting, this._ownerContent, this._repo);
}

@test
Expand Down
8 changes: 6 additions & 2 deletions test/ContentReferenceFieldTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ export class ContentReferenceFieldTests {
private _loadedRef: ContentReferenceField<Task>;

private _repo: MockRepository;

private _ownerContent: Task;

// tslint:disable-next-line:naming-convention
public before() {
this._repo = new MockRepository();
this._repo.Authentication.StateSubject.next(LoginState.Authenticated);
this._ownerContent = this._repo.HandleLoadedContent({Id: 123765, Path: 'Root/Tests', Name: 'TestOwnerContent'}, Task);

this._loadedRef = new ContentReferenceField(this._repo.HandleLoadedContent<Task>({
Id: 1,
Path: 'root/a/b',
Name: 'Name',
Type: 'Task',
DueText: 'testDueText'
}), {} as ReferenceFieldSetting, this._repo);
}), {} as ReferenceFieldSetting, this._ownerContent, this._repo);
this._unloadedRef = new ContentReferenceField({
__deferred: {
uri: 'a/b/c'
}
} as DeferredObject, {} as ReferenceFieldSetting, this._repo);
} as DeferredObject, {} as ReferenceFieldSetting, this._ownerContent, this._repo);
}

@test
Expand Down
38 changes: 19 additions & 19 deletions test/ContentTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,22 +591,22 @@ export const contentTests = describe('Content', () => {
]
}
});
contentSaved.Actions().subscribe((actions) => {
contentSaved.GetActions().subscribe((actions) => {
expect(actions[0].Name).to.be.eq('Action1');
done();
}, done);
expect(contentSaved.Actions()).to.be.instanceof(Observable);
expect(contentSaved.GetActions()).to.be.instanceof(Observable);
});

});
describe('#Actions()', () => {
it('should return an Observable object', () => {
expect(contentSaved.Actions()).to.be.instanceof(Observable);
expect(contentSaved.GetActions()).to.be.instanceof(Observable);
});
});
describe('#Actions()', () => {
it('should return an Observable object', () => {
expect(contentSaved.Actions('ListItem')).to.be.instanceof(Observable);
expect(contentSaved.GetActions('ListItem')).to.be.instanceof(Observable);
});
});
describe('#GetAllowedChildTypes()', () => {
Expand All @@ -625,7 +625,7 @@ export const contentTests = describe('Content', () => {
});
});
it('should return an Observable object', () => {
expect(content.GetAllowedChildTypes({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.GetAllowedChildTypes({ select: ['Name'] })).to.be.instanceof(Observable);
});
});
describe('#GetEffectiveAllowedChildTypes()', () => {
Expand All @@ -638,51 +638,51 @@ export const contentTests = describe('Content', () => {
});
describe('#GetOwner()', () => {
it('should return an Observable object', () => {
expect(content.GetOwner()).to.be.instanceof(Observable);
expect(contentSaved.GetOwner()).to.be.instanceof(Observable);
});
});
describe('#GetOwner()', () => {
it('should return an Observable object', () => {
expect(content.GetOwner({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.GetOwner({ select: ['Name'] })).to.be.instanceof(Observable);
});
});
describe('#Creator()', () => {
it('should return an Observable object', () => {
expect(content.Creator()).to.be.instanceof(Observable);
expect(contentSaved.Creator()).to.be.instanceof(Observable);
});
});
describe('#Creator()', () => {
it('should return an Observable object', () => {
expect(content.Creator({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.Creator({ select: ['Name'] })).to.be.instanceof(Observable);
});
});
describe('#Modifier()', () => {
it('should return an Observable object', () => {
expect(content.Modifier()).to.be.instanceof(Observable);
expect(contentSaved.Modifier()).to.be.instanceof(Observable);
});
});
describe('#Modifier()', () => {
it('should return an Observable object', () => {
expect(content.Modifier({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.Modifier({ select: ['Name'] })).to.be.instanceof(Observable);
});
});
describe('#CheckedOutBy()', () => {
it('should return an Observable object', () => {
expect(content.CheckedOutBy()).to.be.instanceof(Observable);
expect(contentSaved.CheckedOutBy()).to.be.instanceof(Observable);
});
});
describe('#CheckedOutBy()', () => {
it('should return an Observable object', () => {
expect(content.CheckedOutBy({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.CheckedOutBy({ select: ['Name'] })).to.be.instanceof(Observable);
});
});
describe('#Children()', () => {
it('should return an Observable object', () => {
expect(content.Children()).to.be.instanceof(Observable);
expect(contentSaved.Children()).to.be.instanceof(Observable);
});

it('should return an Observable object', () => {
expect(content.Children({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.Children({ select: ['Name'] })).to.be.instanceof(Observable);
});

it('should throw error if no path provided', () => {
Expand Down Expand Up @@ -712,22 +712,22 @@ export const contentTests = describe('Content', () => {
});
describe('#Versions()', () => {
it('should return an Observable object', () => {
expect(content.GetVersions()).to.be.instanceof(Observable);
expect(contentSaved.GetVersions()).to.be.instanceof(Observable);
});
});
describe('#Versions()', () => {
it('should return an Observable object', () => {
expect(content.GetVersions({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.GetVersions({ select: ['Name'] })).to.be.instanceof(Observable);
});
});
describe('#Workspace()', () => {
it('should return an Observable object', () => {
expect(content.GetWorkspace()).to.be.instanceof(Observable);
expect(contentSaved.GetWorkspace()).to.be.instanceof(Observable);
});
});
describe('#Workspace()', () => {
it('should return an Observable object', () => {
expect(content.GetWorkspace({ select: ['Name'] })).to.be.instanceof(Observable);
expect(contentSaved.GetWorkspace({ select: ['Name'] })).to.be.instanceof(Observable);
});
});
describe('#Checkout()', () => {
Expand Down

0 comments on commit 33a4f23

Please sign in to comment.