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

Commit 33a4f23

Browse files
committed
Merge branch 'release/3.0.1'
2 parents cc0e523 + 5dad806 commit 33a4f23

File tree

9 files changed

+58
-34
lines changed

9 files changed

+58
-34
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sn-client-js",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "A JavaScript client for Sense/Net ECM that makes it easy to use the REST API of the Content Repository.",
55
"main": "dist/src/SN.js",
66
"files": [

src/Authentication/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* @module Authentication
33
* @preferred
44
* @description This module that contains authentication-related classes, types and interfaces
5+
*
6+
* <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>
57
*/ /** */
68

79
export * from './IAuthenticationService';

src/Content/ContentInternal.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
referenceSettings.forEach((f) => {
168168

169169
if (!this._fieldHandlerCache[f.Name]) {
170-
this._fieldHandlerCache[f.Name] = f.AllowMultiple ? new ContentListReferenceField(this[f.Name], f, this._repository) : new ContentReferenceField(this[f.Name], f, this._repository);
170+
this._fieldHandlerCache[f.Name] = f.AllowMultiple ? new ContentListReferenceField(this[f.Name], f, this, this._repository) : new ContentReferenceField(this[f.Name], f, this, this._repository);
171171
} else {
172172
this._fieldHandlerCache[f.Name].HandleLoaded(this[f.Name]);
173173
}
@@ -187,7 +187,7 @@
187187
if (isSavedContent<T>(this)) {
188188
return this as SavedContent<T>;
189189
}
190-
throw new Error('Contnet is not saved.');
190+
throw new Error('Content is not saved.');
191191
}
192192

193193
/**
@@ -467,14 +467,20 @@
467467
* @param {string} scenario
468468
* @returns {Observable<ActionModel[]>} Returns an RxJS observable that you can subscribe of in your code.
469469
* ```
470-
* content.Actions('ListItem')
470+
* content.GetActions('ListItem')
471471
* .subscribe(response => {
472472
* console.log(response);
473473
* },
474474
* error: error => console.error('something wrong occurred: ' + error.responseJSON.error.message.value));
475475
* ```
476476
*/
477-
public Actions(scenario?: string): Observable<ActionModel[]> {
477+
public Actions(scenario?: string): Observable<ActionModel[]> {
478+
// tslint:disable-next-line:no-console
479+
console.warn(`Method 'content.Action() is deprecated' and will be removed. Please use content.GetActions() instead`);
480+
return this.GetActions(scenario);
481+
}
482+
483+
public GetActions(scenario?: string): Observable<ActionModel[]> {
478484
return this._odata.Get({
479485
path: ODataHelper.joinPaths(this.GetFullPath(), 'Actions'),
480486
params: {

src/Content/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
* @module Content
33
* @preferred
44
*
5-
* @description Top level base type of sense NET's Type hierarchy.
6-
*
5+
* @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,
6+
* but it has the basic methods implemented that can be called on obejcts with derived types. Unlike other Content Types it is not autogenerated.
77
* 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,
88
* but it has the basic methods implemented that can be called on obejcts with derived types.
9+
* <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>
910
*
1011
* Unlike other Content Types it is not autogenerated.
1112
*

src/ContentReferences.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DeferredObject } from './ComplexTypes';
77
import { IContent, isDeferred, isIContent, SavedContent } from './Content';
88
import { ReferenceFieldSetting } from './FieldSettings';
99
import { IODataParams } from './ODataApi/ODataParams';
10+
import { joinPaths } from './ODataHelper';
1011
import { FinializedQuery } from './Query';
1112
import { BaseRepository } from './Repository/BaseRepository';
1213
import { ContentTypes, isIContentList } from './SN';
@@ -101,10 +102,12 @@ export class ContentReferenceField<T extends IContent> extends ReferenceAbstract
101102
* @returns {Observable<T>} An observable that will publish the referenced content
102103
*/
103104
public GetContent(odataOptions?: IODataParams<T>): Observable<SavedContent<T>> {
104-
if (this._contentReference !== undefined) {
105+
if (!this._ownerContent.IsSaved || this._contentReference !== undefined) {
105106
return Observable.of(this._contentReference);
106107
}
107-
const request = this.Repository.GetODataApi().Get({ path: this._referenceUrl, params: odataOptions })
108+
const request = this.Repository.GetODataApi().Get({
109+
path: this._referenceUrl || joinPaths(this._ownerContent.GetFullPath(), this.FieldSetting.Name),
110+
params: odataOptions })
108111
.map((r) => {
109112
return r && r.d && this.Repository.HandleLoadedContent<T>(r.d);
110113
}).share();
@@ -137,6 +140,7 @@ export class ContentReferenceField<T extends IContent> extends ReferenceAbstract
137140

138141
constructor(fieldData: DeferredObject | SavedContent<T>,
139142
public readonly FieldSetting: ReferenceFieldSetting,
143+
private readonly _ownerContent: SavedContent,
140144
public readonly Repository: BaseRepository) {
141145
super();
142146
this.HandleLoaded(fieldData);
@@ -174,12 +178,12 @@ export class ContentListReferenceField<T extends IContent> extends ReferenceAbst
174178
* @returns {Observable<T[]>} An observable that will publish the list of the referenced content
175179
*/
176180
public GetContent(odataOptions?: IODataParams<T>): Observable<SavedContent<T>[]> {
177-
if (this._contentReferences) {
181+
if (!this._ownerContent.IsSaved || this._contentReferences) {
178182
return Observable.of(this._contentReferences);
179183
}
180184
//
181185
const request = this.Repository.GetODataApi().Fetch<T>({
182-
path: this._referenceUrl,
186+
path: this._referenceUrl || joinPaths(this._ownerContent.GetFullPath(), this.FieldSetting.Name),
183187
params: odataOptions
184188
}).map((resp) => {
185189
return resp && resp.d && resp.d.results.map((c) => this.Repository.HandleLoadedContent<T>(c)) || [];
@@ -217,6 +221,8 @@ export class ContentListReferenceField<T extends IContent> extends ReferenceAbst
217221

218222
constructor(fieldData: DeferredObject | T[],
219223
public readonly FieldSetting: ReferenceFieldSetting,
224+
private readonly _ownerContent: SavedContent,
225+
220226
public readonly Repository: BaseRepository) {
221227
super();
222228
this.HandleLoaded(fieldData);

src/Query/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* @preferred
44
*
55
* @description Classes and Methods for creating, manipulating and executing content queries in sensenet ECM.
6+
*
7+
* <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>
68
*/ /** */
79

810
export * from './Query';

test/ContentListReferenceFieldTests.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ export class ContentListReferenceFieldTests {
1717
private _unloadedRef: ContentListReferenceField<Task>;
1818
private _loadedRef: ContentListReferenceField<Task>;
1919

20+
private _ownerContent: Task;
21+
2022
private _repo: MockRepository;
2123
// tslint:disable-next-line:naming-convention
2224
public before() {
2325
this._repo = new MockRepository();
26+
this._ownerContent = this._repo.HandleLoadedContent({Id: 123765, Path: 'Root/Tests', Name: 'TestOwnerContent'}, Task);
2427
this._repo.Authentication.StateSubject.next(LoginState.Authenticated);
2528
this._loadedRef = new ContentListReferenceField(
2629
[{
@@ -29,12 +32,12 @@ export class ContentListReferenceFieldTests {
2932
Name: 'Name',
3033
Type: 'Task',
3134
DueText: 'testDueText'
32-
} as Task], {} as ReferenceFieldSetting, this._repo);
35+
} as Task], {} as ReferenceFieldSetting, this._ownerContent, this._repo);
3336
this._unloadedRef = new ContentListReferenceField({
3437
__deferred: {
3538
uri: 'a/b/c'
3639
}
37-
} as DeferredObject, {} as ReferenceFieldSetting, this._repo);
40+
} as DeferredObject, {} as ReferenceFieldSetting, this._ownerContent, this._repo);
3841
}
3942

4043
@test

test/ContentReferenceFieldTests.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,27 @@ export class ContentReferenceFieldTests {
1818
private _loadedRef: ContentReferenceField<Task>;
1919

2020
private _repo: MockRepository;
21+
22+
private _ownerContent: Task;
23+
2124
// tslint:disable-next-line:naming-convention
2225
public before() {
2326
this._repo = new MockRepository();
2427
this._repo.Authentication.StateSubject.next(LoginState.Authenticated);
28+
this._ownerContent = this._repo.HandleLoadedContent({Id: 123765, Path: 'Root/Tests', Name: 'TestOwnerContent'}, Task);
2529

2630
this._loadedRef = new ContentReferenceField(this._repo.HandleLoadedContent<Task>({
2731
Id: 1,
2832
Path: 'root/a/b',
2933
Name: 'Name',
3034
Type: 'Task',
3135
DueText: 'testDueText'
32-
}), {} as ReferenceFieldSetting, this._repo);
36+
}), {} as ReferenceFieldSetting, this._ownerContent, this._repo);
3337
this._unloadedRef = new ContentReferenceField({
3438
__deferred: {
3539
uri: 'a/b/c'
3640
}
37-
} as DeferredObject, {} as ReferenceFieldSetting, this._repo);
41+
} as DeferredObject, {} as ReferenceFieldSetting, this._ownerContent, this._repo);
3842
}
3943

4044
@test

test/ContentTests.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -591,22 +591,22 @@ export const contentTests = describe('Content', () => {
591591
]
592592
}
593593
});
594-
contentSaved.Actions().subscribe((actions) => {
594+
contentSaved.GetActions().subscribe((actions) => {
595595
expect(actions[0].Name).to.be.eq('Action1');
596596
done();
597597
}, done);
598-
expect(contentSaved.Actions()).to.be.instanceof(Observable);
598+
expect(contentSaved.GetActions()).to.be.instanceof(Observable);
599599
});
600600

601601
});
602602
describe('#Actions()', () => {
603603
it('should return an Observable object', () => {
604-
expect(contentSaved.Actions()).to.be.instanceof(Observable);
604+
expect(contentSaved.GetActions()).to.be.instanceof(Observable);
605605
});
606606
});
607607
describe('#Actions()', () => {
608608
it('should return an Observable object', () => {
609-
expect(contentSaved.Actions('ListItem')).to.be.instanceof(Observable);
609+
expect(contentSaved.GetActions('ListItem')).to.be.instanceof(Observable);
610610
});
611611
});
612612
describe('#GetAllowedChildTypes()', () => {
@@ -625,7 +625,7 @@ export const contentTests = describe('Content', () => {
625625
});
626626
});
627627
it('should return an Observable object', () => {
628-
expect(content.GetAllowedChildTypes({ select: ['Name'] })).to.be.instanceof(Observable);
628+
expect(contentSaved.GetAllowedChildTypes({ select: ['Name'] })).to.be.instanceof(Observable);
629629
});
630630
});
631631
describe('#GetEffectiveAllowedChildTypes()', () => {
@@ -638,51 +638,51 @@ export const contentTests = describe('Content', () => {
638638
});
639639
describe('#GetOwner()', () => {
640640
it('should return an Observable object', () => {
641-
expect(content.GetOwner()).to.be.instanceof(Observable);
641+
expect(contentSaved.GetOwner()).to.be.instanceof(Observable);
642642
});
643643
});
644644
describe('#GetOwner()', () => {
645645
it('should return an Observable object', () => {
646-
expect(content.GetOwner({ select: ['Name'] })).to.be.instanceof(Observable);
646+
expect(contentSaved.GetOwner({ select: ['Name'] })).to.be.instanceof(Observable);
647647
});
648648
});
649649
describe('#Creator()', () => {
650650
it('should return an Observable object', () => {
651-
expect(content.Creator()).to.be.instanceof(Observable);
651+
expect(contentSaved.Creator()).to.be.instanceof(Observable);
652652
});
653653
});
654654
describe('#Creator()', () => {
655655
it('should return an Observable object', () => {
656-
expect(content.Creator({ select: ['Name'] })).to.be.instanceof(Observable);
656+
expect(contentSaved.Creator({ select: ['Name'] })).to.be.instanceof(Observable);
657657
});
658658
});
659659
describe('#Modifier()', () => {
660660
it('should return an Observable object', () => {
661-
expect(content.Modifier()).to.be.instanceof(Observable);
661+
expect(contentSaved.Modifier()).to.be.instanceof(Observable);
662662
});
663663
});
664664
describe('#Modifier()', () => {
665665
it('should return an Observable object', () => {
666-
expect(content.Modifier({ select: ['Name'] })).to.be.instanceof(Observable);
666+
expect(contentSaved.Modifier({ select: ['Name'] })).to.be.instanceof(Observable);
667667
});
668668
});
669669
describe('#CheckedOutBy()', () => {
670670
it('should return an Observable object', () => {
671-
expect(content.CheckedOutBy()).to.be.instanceof(Observable);
671+
expect(contentSaved.CheckedOutBy()).to.be.instanceof(Observable);
672672
});
673673
});
674674
describe('#CheckedOutBy()', () => {
675675
it('should return an Observable object', () => {
676-
expect(content.CheckedOutBy({ select: ['Name'] })).to.be.instanceof(Observable);
676+
expect(contentSaved.CheckedOutBy({ select: ['Name'] })).to.be.instanceof(Observable);
677677
});
678678
});
679679
describe('#Children()', () => {
680680
it('should return an Observable object', () => {
681-
expect(content.Children()).to.be.instanceof(Observable);
681+
expect(contentSaved.Children()).to.be.instanceof(Observable);
682682
});
683683

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

688688
it('should throw error if no path provided', () => {
@@ -712,22 +712,22 @@ export const contentTests = describe('Content', () => {
712712
});
713713
describe('#Versions()', () => {
714714
it('should return an Observable object', () => {
715-
expect(content.GetVersions()).to.be.instanceof(Observable);
715+
expect(contentSaved.GetVersions()).to.be.instanceof(Observable);
716716
});
717717
});
718718
describe('#Versions()', () => {
719719
it('should return an Observable object', () => {
720-
expect(content.GetVersions({ select: ['Name'] })).to.be.instanceof(Observable);
720+
expect(contentSaved.GetVersions({ select: ['Name'] })).to.be.instanceof(Observable);
721721
});
722722
});
723723
describe('#Workspace()', () => {
724724
it('should return an Observable object', () => {
725-
expect(content.GetWorkspace()).to.be.instanceof(Observable);
725+
expect(contentSaved.GetWorkspace()).to.be.instanceof(Observable);
726726
});
727727
});
728728
describe('#Workspace()', () => {
729729
it('should return an Observable object', () => {
730-
expect(content.GetWorkspace({ select: ['Name'] })).to.be.instanceof(Observable);
730+
expect(contentSaved.GetWorkspace({ select: ['Name'] })).to.be.instanceof(Observable);
731731
});
732732
});
733733
describe('#Checkout()', () => {

0 commit comments

Comments
 (0)