1 | import { __decorate } from "tslib";
|
2 | import { _SPCollection, spInvokableFactory, deleteable, _SPInstance, _SPQueryable, } from "../spqueryable.js";
|
3 | import { body } from "@pnp/queryable";
|
4 | import { defaultPath } from "../decorators.js";
|
5 | import { spPost, spPostMerge } from "../operations.js";
|
6 | import { extractWebUrl } from "../index.js";
|
7 | import { combine } from "@pnp/core";
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export class _NavigationNodes extends _SPCollection {
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 | getById(id) {
|
19 | return NavigationNode(this).concat(`(${id})`);
|
20 | }
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | async add(title, url, visible = true) {
|
29 | const postBody = body({
|
30 | IsVisible: visible,
|
31 | Title: title,
|
32 | Url: url,
|
33 | });
|
34 | const data = await spPost(NavigationNodes(this, null), postBody);
|
35 | return {
|
36 | data,
|
37 | node: this.getById(data.Id),
|
38 | };
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | moveAfter(nodeId, previousNodeId) {
|
47 | const postBody = body({
|
48 | nodeId: nodeId,
|
49 | previousNodeId: previousNodeId,
|
50 | });
|
51 | return spPost(NavigationNodes(this, "MoveAfter"), postBody);
|
52 | }
|
53 | }
|
54 | export const NavigationNodes = spInvokableFactory(_NavigationNodes);
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | export class _NavigationNode extends _SPInstance {
|
60 | constructor() {
|
61 | super(...arguments);
|
62 | this.delete = deleteable();
|
63 | }
|
64 | |
65 |
|
66 |
|
67 | get children() {
|
68 | return NavigationNodes(this, "children");
|
69 | }
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 | async update(properties) {
|
76 | const data = await spPostMerge(this, body(properties));
|
77 | return {
|
78 | data,
|
79 | node: this,
|
80 | };
|
81 | }
|
82 | }
|
83 | export const NavigationNode = spInvokableFactory(_NavigationNode);
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | let _Navigation = class _Navigation extends _SPQueryable {
|
89 | |
90 |
|
91 |
|
92 |
|
93 | get quicklaunch() {
|
94 | return NavigationNodes(this, "quicklaunch");
|
95 | }
|
96 | |
97 |
|
98 |
|
99 |
|
100 | get topNavigationBar() {
|
101 | return NavigationNodes(this, "topnavigationbar");
|
102 | }
|
103 | };
|
104 | _Navigation = __decorate([
|
105 | defaultPath("navigation")
|
106 | ], _Navigation);
|
107 | export { _Navigation };
|
108 | export const Navigation = spInvokableFactory(_Navigation);
|
109 |
|
110 |
|
111 |
|
112 | export class _NavigationService extends _SPQueryable {
|
113 | constructor(base = null, path) {
|
114 | super(base, path);
|
115 | this._url = combine(extractWebUrl(this._url), "_api/navigation", path);
|
116 | }
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | getMenuState(menuNodeKey = null, depth = 10, mapProviderName = null, customProperties = null) {
|
126 | return spPost(NavigationService(this, "MenuState"), body({
|
127 | customProperties,
|
128 | depth,
|
129 | mapProviderName,
|
130 | menuNodeKey,
|
131 | }));
|
132 | }
|
133 | |
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | getMenuNodeKey(currentUrl, mapProviderName = null) {
|
140 | return spPost(NavigationService(this, "MenuNodeKey"), body({
|
141 | currentUrl,
|
142 | mapProviderName,
|
143 | }));
|
144 | }
|
145 | }
|
146 | export const NavigationService = (base, path) => new _NavigationService(base, path);
|
147 |
|
\ | No newline at end of file |