-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemType.jsx
More file actions
188 lines (188 loc) · 8.5 KB
/
ItemType.jsx
File metadata and controls
188 lines (188 loc) · 8.5 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
ItemType = React.createClass({
mixins: [ReactMeteorData],
getMeteorData() {
var itemtype = ItemTypes.findOne({name: this.props.itemname});
var propertytype;
if (!itemtype) {
propertytype = PropertyTypes.findOne({name: this.props.itemname});
} else {
itemtype.properties = itemtype.properties.map((name, i)=>{
return PropertyTypes.findOne({name: name});
});
var extendItemType2 = function(type) {
for (var i in type.inheritsFrom) {
var parent = ItemTypes.findOne({name: type.inheritsFrom[i]});
parent.properties = parent.properties.map((name, i)=>{
return PropertyTypes.findOne({name: name});
});
extendItemType2(parent);
type.inheritedProperties = [{from: parent.name, properties: parent.properties}];
if (parent.inheritedProperties) {
type.inheritedProperties = type.inheritedProperties.concat(parent.inheritedProperties);
}
}
}
extendItemType2(itemtype);
}
return {
itemtype: itemtype,
propertytype: propertytype,
user: Meteor.user()
};
},
render() {
if (this.data.itemtype) {
return <div className='container'>
{/*nagłówek z nazwą typu: */}
<h2>{this.data.itemtype.name}</h2>
<div><b>{this.data.itemtype.description}</b></div>
{this.renderParents()}
{this.renderSameAs(this.data.itemtype.sameAs)}
{this.data.user && this.data.user.GlobalRight ? <div className="row">
<div className="col-md-12">
<button type="button" className="btn btn-info" data-toggle="modal" data-target="#addPropertyModal">
Dodaj właściwość
</button>
</div>
</div> : null}
<table className='table'>
<thead>
<tr className='info'>
<th>Nazwa</th>
<th>Spodziewany typ</th>
<th>Opis</th>
</tr>
</thead>
{this.renderProperties()}
</table>
{/*okno dodawania właściwości: */}
<div className="modal fade" id="addPropertyModal" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Dodaj właściwość</h4>
</div>
<div className="modal-body">
<div>Nazwa:</div>
<input type="text" id='name' className='form-control'/>
<div>Spodziewany typ:</div>
<textarea id='expectedTypes' className='form-control' rows='3' cols='80' >https://schema.org/Text</textarea>
<div>Opis:</div>
<textarea id='description' className='form-control' rows='3' cols='80'></textarea>
<div>Identyczny z:</div>
<input type="text" id='sameAs' className='form-control'/>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-success"
data-dismiss="modal" onClick={this.addProperty}>
Dodaj
</button>
<button type="button" className="btn btn-default" data-dismiss="modal">Anuluj</button>
</div>
</div>
</div>
</div>
</div>
} else if (this.data.propertytype){
return <div className='container'>
{/*nagłówek z nazwą typu: */}
<h2>{this.data.propertytype.name}</h2>
<div>{this.renderSameAs(this.data.propertytype.sameAs)}</div>
<div><b>{this.data.propertytype.description}</b></div>
Spodziewany typ: {this.renderExpectedTypes(this.data.propertytype.expectedTypes)}
</div>
} else {
return null;
}
},
addProperty(event) {
var $modal = $(event.target).closest('.modal-content');
Meteor.call('addItemTypeProperty', this.data.itemtype._id, {
name: $modal.find('#name')[0].value,
expectedTypes: $modal.find('#expectedTypes')[0].value.split(',').map((el)=>{return el.trim()}),
description: $modal.find('#description')[0].value,
sameAs: $modal.find('#sameAs')[0].value
})
},
renderProperties() {
var render = (props, ifBin)=>{
return props.map((el, i)=>{
//var el = PropertyTypes.findOne({name: name});
return <tr>
<td>
{ifBin ? <button type="button" id={i} className="btn btn-xs btn-default"
onClick={this.removeProperty}>
<span className="glyphicon glyphicon-trash"
aria-label="Usuń"></span>
</button> : null} <a href={'/dictionary/'+el.name}>{el.name}</a>
</td>
<td>{this.renderExpectedTypes(el.expectedTypes)}</td>
<td>{el.description}</td>
</tr>
})
}
var arr = [];
arr.push(<thead><tr className='active'><td colSpan='3'>
<b>Właściwości z <a href={'/dictionary/'+this.data.itemtype.name}>{this.data.itemtype.name}:</a></b>
</td></tr></thead>);
arr = arr.concat(<tbody>{render(this.data.itemtype.properties, this.data.user && this.data.user.GlobalRight)}</tbody>);
var p = this.data.itemtype.inheritedProperties;
for (var i in p) {
arr.push(<thead><tr className='active'><th colSpan='3'>
<b>Właściwości z <a href={'/dictionary/'+p[i].from}>{p[i].from}:</a></b>
</th></tr></thead>)
arr = arr.concat(<tbody>{render(p[i].properties)}</tbody>);
}
return arr;
},
renderExpectedTypes(arr) {
return arr.map((el, i)=>{
if (el) {
var splitString = el.split('/');
var name = splitString[splitString.length-1];
if (i < arr.length-1) {
return <span><a href={el}>{name}</a> lub </span>
} else {
return <span><a href={el}>{name}</a></span>
}
} else {
return null;
}
})
},
renderParents() {
if (this.data.itemtype.inheritsFrom && this.data.itemtype.inheritsFrom.length > 0) {
var arr = this.data.itemtype.inheritsFrom;
return <div>Dziedziczy po: {arr.map((el, i)=>{
if (i < arr.length-1) {
return <span><a href={'/dictionary/'+el}>{el}</a>, </span>
} else {
return <span><a href={'/dictionary/'+el}>{el}</a></span>
}
})}</div>
}
},
renderSameAs(el) {
/*if (this.data.itemtype.sameAs && this.data.itemtype.sameAs.length > 0) {
var arr = this.data.itemtype.sameAs;
return <div>Identyczny z: {arr.map((el, i)=>{
var splitString = el.split('/');
var name = splitString[splitString.length-1];
if (i < arr.length-1) {
return <span><a href={el}>{name}</a>, </span>
} else {
return <span><a href={el}>{name}</a></span>
}
})}</div>
}*/
if (el) {
var splitString = el.split('/');
var name = splitString[splitString.length-1];
return <span>Identyczny z: <a href={el}>{name}</a></span>;
}
},
removeProperty(event) {
Meteor.call('removeItemTypeProperty', this.data.itemtype._id, event.currentTarget.id)
}
});