-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-resource.html
More file actions
156 lines (134 loc) · 4.59 KB
/
api-resource.html
File metadata and controls
156 lines (134 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<dom-module id="apigility-resource">
<template>
<content></content>
</template>
<script>
'use strict';
Polymer({
is: 'apigility-resource',
properties: {
resourceName: {
type: String,
value: null
},
iAmEntity: {
type: Boolean,
value: false
},
hasIdentifier: {
type: Boolean,
value: false
},
identifier: {
type: String,
value: null
},
readyResource: {
type: Boolean,
readOnly: true,
value: false
},
countEvent: {
type: Number,
readOnly: true
}
},
observers: [
'observePathParams(resourceName, identifier, hasIdentifier)'
],
listeners: {
'change-local-path':'changeLocalPath'
},
changeLocalPath: function (event) {
if (this.countEvent === null || this.countEvent === undefined) {
this._setCountEvent(0);
}
this._setCountEvent(this.countEvent + 1);
if (this.countResource() <= this.countEvent) {
this._setReadyResource(true);
}
if (this.parentElement.is !== 'apigility-resource') {
if (this.readyResource) {
if (this.countResource() == this.countEvent) {
this.fire('ready-path');
} else {
this.fire('change-path');
}
}
}
},
observePathParams: function (resourceName, identifier, hasIdentifier) {
var event = {"resourceName": this.resourceName};
if (resourceName && hasIdentifier === false) {
this.fire('change-local-path', event);
}
if (resourceName && identifier && hasIdentifier === true) {
this.fire('change-local-path', event);
}
},
_getNestedResource: function () {
return this.querySelector('apigility-resource');
},
getPath: function () {
return "/" + this.resourceName + ((this.identifier) ? "/" + this.identifier : "");
},
/**
* Return the string that rapresent the path of url
*
* @returns {string}
*/
getFullPath: function () {
var nested = this._getNestedResource();
var url = '';
if (nested) {
url = url + nested.getFullPath();
}
return this.getPath() + url;
},
/**
* Set the identifier of the leaf apigility-resource element
*
* @returns {boolean}
*/
setNestedId: function (id) {
var nested = this._getNestedResource();
if (nested) {
return nested.setNestedId(id);
} else {
this.identifier = id;
this.hasIdentifier = true;
}
return this;
},
/**
* Return true if the element has not nested apigility-resource, it's a leaf
*
* @returns {boolean}
*/
isEntity: function () {
var nested = this._getNestedResource();
if (this.iAmEntity && this.identifier) {
return true;
} else if (nested) {
return nested.isEntity();
} else if (this.identifier) {
return true;
}
return false;
},
/**
* Return the count of the nested apigility-resource
*
* @returns {number}
*/
countResource: function () {
var nested = this._getNestedResource();
var count = 0;
if (nested) {
count += nested.countResource();
}
return count += 1;
}
});
</script>
</dom-module>