wf_node_api 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/Gemfile +28 -0
  4. data/Gemfile.lock +66 -0
  5. data/LICENSE +340 -0
  6. data/Makefile +19 -0
  7. data/README.md +78 -0
  8. data/Rakefile +2 -0
  9. data/Vagrantfile +102 -0
  10. data/_docs/api/Api/NodeApi.html +123 -0
  11. data/_docs/api/Api.html +149 -0
  12. data/_docs/api/Config/Check.html +331 -0
  13. data/_docs/api/Config.html +115 -0
  14. data/_docs/api/ConfigCheck.html +365 -0
  15. data/_docs/api/ContainerManager.html +1632 -0
  16. data/_docs/api/ContainerManagerAdapter/Lxc.html +1352 -0
  17. data/_docs/api/ContainerManagerAdapter/Vserver.html +1358 -0
  18. data/_docs/api/ContainerManagerAdapter.html +151 -0
  19. data/_docs/api/Error/NotFound.html +134 -0
  20. data/_docs/api/Error.html +115 -0
  21. data/_docs/api/NotFoundError.html +157 -0
  22. data/_docs/api/OS.html +234 -0
  23. data/_docs/api/ResourceManager.html +322 -0
  24. data/_docs/api/ResourceManagerAdapter/Linux.html +326 -0
  25. data/_docs/api/ResourceManagerAdapter.html +149 -0
  26. data/_docs/api/WfNodeApi.html +163 -0
  27. data/_docs/api/_index.html +239 -0
  28. data/_docs/api/class_list.html +58 -0
  29. data/_docs/api/css/common.css +1 -0
  30. data/_docs/api/css/full_list.css +57 -0
  31. data/_docs/api/css/style.css +339 -0
  32. data/_docs/api/file.README.html +146 -0
  33. data/_docs/api/file_list.html +60 -0
  34. data/_docs/api/frames.html +26 -0
  35. data/_docs/api/index.html +146 -0
  36. data/_docs/api/js/app.js +219 -0
  37. data/_docs/api/js/full_list.js +181 -0
  38. data/_docs/api/js/jquery.js +4 -0
  39. data/_docs/api/method_list.html +273 -0
  40. data/_docs/api/top-level-namespace.html +244 -0
  41. data/_docs/rest/api_data.js +1 -0
  42. data/_docs/rest/api_data.json +1 -0
  43. data/_docs/rest/api_project.js +1 -0
  44. data/_docs/rest/api_project.json +1 -0
  45. data/_docs/rest/css/style.css +538 -0
  46. data/_docs/rest/header.md +3 -0
  47. data/_docs/rest/img/favicon.ico +0 -0
  48. data/_docs/rest/img/glyphicons-halflings-white.png +0 -0
  49. data/_docs/rest/img/glyphicons-halflings.png +0 -0
  50. data/_docs/rest/index.html +658 -0
  51. data/_docs/rest/locales/de.js +25 -0
  52. data/_docs/rest/locales/fr.js +25 -0
  53. data/_docs/rest/locales/locale.js +43 -0
  54. data/_docs/rest/locales/nl.js +25 -0
  55. data/_docs/rest/locales/pl.js +25 -0
  56. data/_docs/rest/locales/pt_br.js +25 -0
  57. data/_docs/rest/locales/ru.js +25 -0
  58. data/_docs/rest/locales/zh.js +25 -0
  59. data/_docs/rest/main.js +691 -0
  60. data/_docs/rest/utils/handlebars_helper.js +327 -0
  61. data/_docs/rest/utils/send_sample_request.js +158 -0
  62. data/_docs/rest/vendor/bootstrap-responsive.min.css +9 -0
  63. data/_docs/rest/vendor/bootstrap.min.css +9 -0
  64. data/_docs/rest/vendor/bootstrap.min.js +6 -0
  65. data/_docs/rest/vendor/diff_match_patch.min.js +49 -0
  66. data/_docs/rest/vendor/handlebars.min.js +28 -0
  67. data/_docs/rest/vendor/jquery.min.js +4 -0
  68. data/_docs/rest/vendor/lodash.min.js +61 -0
  69. data/_docs/rest/vendor/path-to-regexp/LICENSE +21 -0
  70. data/_docs/rest/vendor/path-to-regexp/index.js +205 -0
  71. data/_docs/rest/vendor/polyfill.js +100 -0
  72. data/_docs/rest/vendor/prettify/lang-apollo.js +2 -0
  73. data/_docs/rest/vendor/prettify/lang-basic.js +3 -0
  74. data/_docs/rest/vendor/prettify/lang-clj.js +18 -0
  75. data/_docs/rest/vendor/prettify/lang-css.js +2 -0
  76. data/_docs/rest/vendor/prettify/lang-dart.js +3 -0
  77. data/_docs/rest/vendor/prettify/lang-erlang.js +2 -0
  78. data/_docs/rest/vendor/prettify/lang-go.js +1 -0
  79. data/_docs/rest/vendor/prettify/lang-hs.js +2 -0
  80. data/_docs/rest/vendor/prettify/lang-lisp.js +3 -0
  81. data/_docs/rest/vendor/prettify/lang-llvm.js +1 -0
  82. data/_docs/rest/vendor/prettify/lang-lua.js +2 -0
  83. data/_docs/rest/vendor/prettify/lang-matlab.js +6 -0
  84. data/_docs/rest/vendor/prettify/lang-ml.js +2 -0
  85. data/_docs/rest/vendor/prettify/lang-mumps.js +2 -0
  86. data/_docs/rest/vendor/prettify/lang-n.js +4 -0
  87. data/_docs/rest/vendor/prettify/lang-pascal.js +3 -0
  88. data/_docs/rest/vendor/prettify/lang-proto.js +1 -0
  89. data/_docs/rest/vendor/prettify/lang-r.js +2 -0
  90. data/_docs/rest/vendor/prettify/lang-rd.js +1 -0
  91. data/_docs/rest/vendor/prettify/lang-scala.js +2 -0
  92. data/_docs/rest/vendor/prettify/lang-sql.js +2 -0
  93. data/_docs/rest/vendor/prettify/lang-tcl.js +3 -0
  94. data/_docs/rest/vendor/prettify/lang-tex.js +1 -0
  95. data/_docs/rest/vendor/prettify/lang-vb.js +2 -0
  96. data/_docs/rest/vendor/prettify/lang-vhdl.js +3 -0
  97. data/_docs/rest/vendor/prettify/lang-wiki.js +2 -0
  98. data/_docs/rest/vendor/prettify/lang-xq.js +3 -0
  99. data/_docs/rest/vendor/prettify/lang-yaml.js +2 -0
  100. data/_docs/rest/vendor/prettify/prettify.css +1 -0
  101. data/_docs/rest/vendor/prettify/prettify.js +30 -0
  102. data/_docs/rest/vendor/prettify/run_prettify.js +34 -0
  103. data/_docs/rest/vendor/prettify.css +101 -0
  104. data/_docs/rest/vendor/require.min.js +36 -0
  105. data/apidoc.json +23 -0
  106. data/bin/wf_node_api +80 -0
  107. data/lib/wf_node_api/api/node_api.rb +360 -0
  108. data/lib/wf_node_api/config/config_template.erb +50 -0
  109. data/lib/wf_node_api/config_check.rb +50 -0
  110. data/lib/wf_node_api/container_manager.rb +286 -0
  111. data/lib/wf_node_api/container_manager_adapter/lxc.rb +431 -0
  112. data/lib/wf_node_api/container_manager_adapter/vserver.rb +448 -0
  113. data/lib/wf_node_api/error/not_found.rb +27 -0
  114. data/lib/wf_node_api/os.rb +32 -0
  115. data/lib/wf_node_api/resource_manager.rb +49 -0
  116. data/lib/wf_node_api/resource_manager_adapter/linux.rb +53 -0
  117. data/lib/wf_node_api/translations.rb +38 -0
  118. data/lib/wf_node_api/version.rb +28 -0
  119. data/lib/wf_node_api.rb +57 -0
  120. data/manifests/files/dhozac-vserver.repo +4 -0
  121. data/wf-node-api.gemspec +53 -0
  122. metadata +221 -0
@@ -0,0 +1,691 @@
1
+ require.config({
2
+ paths: {
3
+ bootstrap: './vendor/bootstrap.min',
4
+ diffMatchPatch: './vendor/diff_match_patch.min',
5
+ handlebars: './vendor/handlebars.min',
6
+ handlebarsExtended: './utils/handlebars_helper',
7
+ jquery: './vendor/jquery.min',
8
+ locales: './locales/locale',
9
+ lodash: './vendor/lodash.min',
10
+ pathToRegexp: './vendor/path-to-regexp/index',
11
+ prettify: './vendor/prettify/prettify',
12
+ utilsSampleRequest: './utils/send_sample_request',
13
+ },
14
+ shim: {
15
+ bootstrap: {
16
+ deps: ['jquery']
17
+ },
18
+ diffMatchPatch: {
19
+ exports: 'diff_match_patch'
20
+ },
21
+ handlebars: {
22
+ exports: 'Handlebars'
23
+ },
24
+ handlebarsExtended: {
25
+ deps: ['jquery', 'handlebars'],
26
+ exports: 'Handlebars'
27
+ },
28
+ prettify: {
29
+ exports: 'prettyPrint'
30
+ }
31
+ },
32
+ urlArgs: 'v=' + (new Date()).getTime(),
33
+ waitSeconds: 15
34
+ });
35
+
36
+ require([
37
+ 'jquery',
38
+ 'lodash',
39
+ 'locales',
40
+ 'handlebarsExtended',
41
+ './api_project.js',
42
+ './api_data.js',
43
+ 'prettify',
44
+ 'utilsSampleRequest',
45
+ 'bootstrap',
46
+ 'pathToRegexp'
47
+ ], function($, _, locale, Handlebars, apiProject, apiData, prettyPrint, sampleRequest) {
48
+
49
+ // load google web fonts
50
+ loadGoogleFontCss();
51
+
52
+ var api = apiData.api;
53
+
54
+ //
55
+ // Templates
56
+ //
57
+ var templateHeader = Handlebars.compile( $('#template-header').html() );
58
+ var templateFooter = Handlebars.compile( $('#template-footer').html() );
59
+ var templateArticle = Handlebars.compile( $('#template-article').html() );
60
+ var templateCompareArticle = Handlebars.compile( $('#template-compare-article').html() );
61
+ var templateGenerator = Handlebars.compile( $('#template-generator').html() );
62
+ var templateProject = Handlebars.compile( $('#template-project').html() );
63
+ var templateSections = Handlebars.compile( $('#template-sections').html() );
64
+ var templateSidenav = Handlebars.compile( $('#template-sidenav').html() );
65
+
66
+ //
67
+ // apiProject defaults
68
+ //
69
+ if ( ! apiProject.template)
70
+ apiProject.template = {};
71
+
72
+ if (apiProject.template.withCompare == null)
73
+ apiProject.template.withCompare = true;
74
+
75
+ if (apiProject.template.withGenerator == null)
76
+ apiProject.template.withGenerator = true;
77
+
78
+ if (apiProject.template.forceLanguage)
79
+ locale.setLanguage(apiProject.template.forceLanguage);
80
+
81
+ // Setup jQuery Ajax
82
+ $.ajaxSetup(apiProject.template.jQueryAjaxSetup);
83
+
84
+ //
85
+ // Data transform
86
+ //
87
+ // grouped by group
88
+ var apiByGroup = _.groupBy(api, function(entry) {
89
+ return entry.group;
90
+ });
91
+
92
+ // grouped by group and name
93
+ var apiByGroupAndName = {};
94
+ $.each(apiByGroup, function(index, entries) {
95
+ apiByGroupAndName[index] = _.groupBy(entries, function(entry) {
96
+ return entry.name;
97
+ });
98
+ });
99
+
100
+ //
101
+ // sort api within a group by title ASC and custom order
102
+ //
103
+ var newList = [];
104
+ var umlauts = { 'ä': 'ae', 'ü': 'ue', 'ö': 'oe', 'ß': 'ss' }; // TODO: remove in version 1.0
105
+ $.each (apiByGroupAndName, function(index, groupEntries) {
106
+ // get titles from the first entry of group[].name[] (name has versioning)
107
+ var titles = [];
108
+ $.each (groupEntries, function(titleName, entries) {
109
+ var title = entries[0].title;
110
+ if(title !== undefined) {
111
+ title.toLowerCase().replace(/[äöüß]/g, function($0) { return umlauts[$0]; });
112
+ titles.push(title + '#~#' + titleName); // '#~#' keep reference to titleName after sorting
113
+ }
114
+ });
115
+ // sort by name ASC
116
+ titles.sort();
117
+
118
+ // custom order
119
+ if (apiProject.order)
120
+ titles = sortByOrder(titles, apiProject.order, '#~#');
121
+
122
+ // add single elements to the new list
123
+ titles.forEach(function(name) {
124
+ var values = name.split('#~#');
125
+ var key = values[1];
126
+ groupEntries[key].forEach(function(entry) {
127
+ newList.push(entry);
128
+ });
129
+ });
130
+ });
131
+ // api overwrite with ordered list
132
+ api = newList;
133
+
134
+ //
135
+ // Group- and Versionlists
136
+ //
137
+ var apiGroups = {};
138
+ var apiGroupTitles = {};
139
+ var apiVersions = {};
140
+ apiVersions[apiProject.version] = 1;
141
+
142
+ $.each(api, function(index, entry) {
143
+ apiGroups[entry.group] = 1;
144
+ apiGroupTitles[entry.group] = entry.groupTitle || entry.group;
145
+ apiVersions[entry.version] = 1;
146
+ });
147
+
148
+ // sort groups
149
+ apiGroups = Object.keys(apiGroups);
150
+ apiGroups.sort();
151
+
152
+ // custom order
153
+ if (apiProject.order)
154
+ apiGroups = sortByOrder(apiGroups, apiProject.order);
155
+
156
+ // sort versions DESC
157
+ apiVersions = Object.keys(apiVersions);
158
+ apiVersions.sort();
159
+ apiVersions.reverse();
160
+
161
+ //
162
+ // create Navigationlist
163
+ //
164
+ var nav = [];
165
+ apiGroups.forEach(function(group) {
166
+ // Mainmenu entry
167
+ nav.push({
168
+ group: group,
169
+ isHeader: true,
170
+ title: apiGroupTitles[group]
171
+ });
172
+
173
+ // Submenu
174
+ var oldName = '';
175
+ api.forEach(function(entry) {
176
+ if (entry.group === group) {
177
+ if (oldName !== entry.name) {
178
+ nav.push({
179
+ title: entry.title,
180
+ group: group,
181
+ name: entry.name,
182
+ type: entry.type,
183
+ version: entry.version
184
+ });
185
+ } else {
186
+ nav.push({
187
+ title: entry.title,
188
+ group: group,
189
+ hidden: true,
190
+ name: entry.name,
191
+ type: entry.type,
192
+ version: entry.version
193
+ });
194
+ }
195
+ oldName = entry.name;
196
+ }
197
+ });
198
+ });
199
+
200
+ // Mainmenu Header entry
201
+ if (apiProject.header) {
202
+ nav.unshift({
203
+ group: '_',
204
+ isHeader: true,
205
+ title: (apiProject.header.title == null) ? locale.__('General') : apiProject.header.title,
206
+ isFixed: true
207
+ });
208
+ }
209
+
210
+ // Mainmenu Footer entry
211
+ if (apiProject.footer && apiProject.footer.title != null) {
212
+ nav.push({
213
+ group: '_footer',
214
+ isHeader: true,
215
+ title: apiProject.footer.title,
216
+ isFixed: true
217
+ });
218
+ }
219
+
220
+ // render pagetitle
221
+ var title = apiProject.title ? apiProject.title : 'apiDoc: ' + apiProject.name + ' - ' + apiProject.version;
222
+ $(document).attr('title', title);
223
+
224
+ // remove loader
225
+ $('#loader').remove();
226
+
227
+ // render sidenav
228
+ var fields = {
229
+ nav: nav
230
+ };
231
+ $('#sidenav').append( templateSidenav(fields) );
232
+
233
+ // render Generator
234
+ $('#generator').append( templateGenerator(apiProject) );
235
+
236
+ // render Project
237
+ _.extend(apiProject, { versions: apiVersions});
238
+ $('#project').append( templateProject(apiProject) );
239
+
240
+ // render apiDoc, header/footer documentation
241
+ if (apiProject.header)
242
+ $('#header').append( templateHeader(apiProject.header) );
243
+
244
+ if (apiProject.footer)
245
+ $('#footer').append( templateFooter(apiProject.footer) );
246
+
247
+ //
248
+ // Render Sections and Articles
249
+ //
250
+ var articleVersions = {};
251
+ var content = '';
252
+ apiGroups.forEach(function(groupEntry) {
253
+ var articles = [];
254
+ var oldName = '';
255
+ var fields = {};
256
+ var title = groupEntry;
257
+ var description = '';
258
+ articleVersions[groupEntry] = {};
259
+
260
+ // render all articles of a group
261
+ api.forEach(function(entry) {
262
+ if(groupEntry === entry.group) {
263
+ if (oldName !== entry.name) {
264
+ // determine versions
265
+ api.forEach(function(versionEntry) {
266
+ if (groupEntry === versionEntry.group && entry.name === versionEntry.name) {
267
+ if ( ! articleVersions[entry.group][entry.name])
268
+ articleVersions[entry.group][entry.name] = [];
269
+
270
+ articleVersions[entry.group][entry.name].push(versionEntry.version);
271
+ }
272
+ });
273
+ fields = {
274
+ article: entry,
275
+ versions: articleVersions[entry.group][entry.name]
276
+ };
277
+ } else {
278
+ fields = {
279
+ article: entry,
280
+ hidden: true,
281
+ versions: articleVersions[entry.group][entry.name]
282
+ };
283
+ }
284
+
285
+ // add prefix URL for endpoint
286
+ if (apiProject.url)
287
+ fields.article.url = apiProject.url + fields.article.url;
288
+
289
+ addArticleSettings(fields, entry);
290
+
291
+ if (entry.groupTitle)
292
+ title = entry.groupTitle;
293
+
294
+ // TODO: make groupDescription compareable with older versions (not important for the moment)
295
+ if (entry.groupDescription)
296
+ description = entry.groupDescription;
297
+
298
+ articles.push({
299
+ article: templateArticle(fields),
300
+ group: entry.group,
301
+ name: entry.name
302
+ });
303
+ oldName = entry.name;
304
+ }
305
+ });
306
+
307
+ // render Section with Articles
308
+ var fields = {
309
+ group: groupEntry,
310
+ title: title,
311
+ description: description,
312
+ articles: articles
313
+ };
314
+ content += templateSections(fields);
315
+ });
316
+ $('#sections').append( content );
317
+
318
+ // Bootstrap Scrollspy
319
+ var $scrollSpy = $(this).scrollspy({ target: '#scrollingNav', offset: 18 });
320
+ $('[data-spy="scroll"]').each(function () {
321
+ $scrollSpy('refresh');
322
+ });
323
+
324
+ // Content-Scroll on Navigation click.
325
+ $('.sidenav').find('a').on('click', function(e) {
326
+ e.preventDefault();
327
+ var id = $(this).attr('href');
328
+ if ($(id).length > 0)
329
+ $('html,body').animate({ scrollTop: parseInt($(id).offset().top) }, 400);
330
+ window.location.hash = $(this).attr('href');
331
+ });
332
+
333
+ // Quickjump on Pageload to hash position.
334
+ if(window.location.hash) {
335
+ var id = window.location.hash;
336
+ if ($(id).length > 0)
337
+ $('html,body').animate({ scrollTop: parseInt($(id).offset().top) }, 0);
338
+ }
339
+
340
+ /**
341
+ * Check if Parameter (sub) List has a type Field.
342
+ * Example: @apiSuccess varname1 No type.
343
+ * @apiSuccess {String} varname2 With type.
344
+ *
345
+ * @param {Object} fields
346
+ */
347
+ function _hasTypeInFields(fields) {
348
+ var result = false;
349
+ $.each(fields, function(name) {
350
+ if (_.any(fields[name], function(item) { return item.type; }) )
351
+ result = true;
352
+ });
353
+ return result;
354
+ }
355
+
356
+ /**
357
+ * On Template changes, recall plugins.
358
+ */
359
+ function initDynamic() {
360
+ // bootstrap popover
361
+ $('a[data-toggle=popover]')
362
+ .popover()
363
+ .click(function(e) {
364
+ e.preventDefault();
365
+ })
366
+ ;
367
+
368
+ var version = $('#version strong').html();
369
+ $('#sidenav li').removeClass('is-new');
370
+ if (apiProject.template.withCompare) {
371
+ $('#sidenav li[data-version=\'' + version + '\']').each(function(){
372
+ var group = $(this).data('group');
373
+ var name = $(this).data('name');
374
+ var length = $('#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\']').length;
375
+ var index = $('#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\']').index($(this));
376
+ if (length === 1 || index === (length - 1))
377
+ $(this).addClass('is-new');
378
+ });
379
+ }
380
+
381
+ // tabs
382
+ $('.nav-tabs-examples a').click(function (e) {
383
+ e.preventDefault();
384
+ $(this).tab('show');
385
+ });
386
+ $('.nav-tabs-examples').find('a:first').tab('show');
387
+
388
+ // sample request switch
389
+ $('.sample-request-switch').click(function (e) {
390
+ var name = '.' + $(this).attr('name') + '-fields';
391
+ $(name).addClass('hide');
392
+ $(this).parent().next(name).removeClass('hide');
393
+ });
394
+
395
+ // init modules
396
+ sampleRequest.initDynamic();
397
+ }
398
+ initDynamic();
399
+
400
+ // Pre- / Code-Format
401
+ prettyPrint();
402
+
403
+ //
404
+ // HTML-Template specific jQuery-Functions
405
+ //
406
+ // Change Main Version
407
+ $('#versions li.version a').on('click', function(e) {
408
+ e.preventDefault();
409
+
410
+ var selectedVersion = $(this).html();
411
+ $('#version strong').html(selectedVersion);
412
+
413
+ // hide all
414
+ $('article').addClass('hide');
415
+ $('#sidenav li:not(.nav-fixed)').addClass('hide');
416
+
417
+ // show 1st equal or lower Version of each entry
418
+ $('article[data-version]').each(function(index) {
419
+ var group = $(this).data('group');
420
+ var name = $(this).data('name');
421
+ var version = $(this).data('version');
422
+
423
+ if (version <= selectedVersion) {
424
+ if($('article[data-group=\'' + group + '\'][data-name=\'' + name + '\']:visible').length === 0) {
425
+ // enable Article
426
+ $('article[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + version + '\']').removeClass('hide');
427
+ // enable Navigation
428
+ $('#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + version + '\']').removeClass('hide');
429
+ $('#sidenav li.nav-header[data-group=\'' + group + '\']').removeClass('hide');
430
+ }
431
+ }
432
+ });
433
+
434
+ initDynamic();
435
+ return;
436
+ });
437
+
438
+ // compare all article with their predecessor
439
+ $('#compareAllWithPredecessor').on('click', changeAllVersionCompareTo);
440
+
441
+ // change version of an article
442
+ $('article .versions li.version a').on('click', changeVersionCompareTo);
443
+
444
+ // compare url-parameter
445
+ $.urlParam = function(name) {
446
+ var results = new RegExp('[\\?&amp;]' + name + '=([^&amp;#]*)').exec(window.location.href);
447
+ return (results && results[1]) ? results[1] : null;
448
+ };
449
+
450
+ if ($.urlParam('compare')) {
451
+ // URL Paramter ?compare=1 is set
452
+ $('#compareAllWithPredecessor').trigger('click');
453
+
454
+ if (window.location.hash) {
455
+ var id = window.location.hash;
456
+ $('html,body').animate({ scrollTop: parseInt($(id).offset().top) - 18 }, 0);
457
+ }
458
+ }
459
+
460
+ /**
461
+ * Change version of an article to compare it to an other version.
462
+ */
463
+ function changeVersionCompareTo(e) {
464
+ e.preventDefault();
465
+
466
+ var $root = $(this).parents('article');
467
+ var selectedVersion = $(this).html();
468
+ var $button = $root.find('.version');
469
+ var currentVersion = $button.find('strong').html();
470
+ $button.find('strong').html(selectedVersion);
471
+
472
+ var group = $root.data('group');
473
+ var name = $root.data('name');
474
+ var version = $root.data('version');
475
+
476
+ var compareVersion = $root.data('compare-version');
477
+
478
+ if (compareVersion === selectedVersion)
479
+ return;
480
+
481
+ if ( ! compareVersion && version == selectedVersion)
482
+ return;
483
+
484
+ if (compareVersion && articleVersions[group][name][0] === selectedVersion || version === selectedVersion) {
485
+ // the version of the entry is set to the highest version (reset)
486
+ resetArticle(group, name, version);
487
+ } else {
488
+ var $compareToArticle = $('article[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + selectedVersion + '\']');
489
+
490
+ var sourceEntry = {};
491
+ var compareEntry = {};
492
+ $.each(apiByGroupAndName[group][name], function(index, entry) {
493
+ if (entry.version === version)
494
+ sourceEntry = entry;
495
+ if (entry.version === selectedVersion)
496
+ compareEntry = entry;
497
+ });
498
+
499
+ var fields = {
500
+ article: sourceEntry,
501
+ compare: compareEntry,
502
+ versions: articleVersions[group][name]
503
+ };
504
+
505
+ // add unique id
506
+ // TODO: replace all group-name-version in template with id.
507
+ fields.article.id = fields.article.group + '-' + fields.article.name + '-' + fields.article.version;
508
+ fields.article.id = fields.article.id.replace(/\./g, '_');
509
+
510
+ fields.compare.id = fields.compare.group + '-' + fields.compare.name + '-' + fields.compare.version;
511
+ fields.compare.id = fields.compare.id.replace(/\./g, '_');
512
+
513
+ var entry = sourceEntry;
514
+ if (entry.parameter && entry.parameter.fields)
515
+ fields._hasTypeInParameterFields = _hasTypeInFields(entry.parameter.fields);
516
+
517
+ if (entry.error && entry.error.fields)
518
+ fields._hasTypeInErrorFields = _hasTypeInFields(entry.error.fields);
519
+
520
+ if (entry.success && entry.success.fields)
521
+ fields._hasTypeInSuccessFields = _hasTypeInFields(entry.success.fields);
522
+
523
+ if (entry.info && entry.info.fields)
524
+ fields._hasTypeInInfoFields = _hasTypeInFields(entry.info.fields);
525
+
526
+ var entry = compareEntry;
527
+ if (fields._hasTypeInParameterFields !== true && entry.parameter && entry.parameter.fields)
528
+ fields._hasTypeInParameterFields = _hasTypeInFields(entry.parameter.fields);
529
+
530
+ if (fields._hasTypeInErrorFields !== true && entry.error && entry.error.fields)
531
+ fields._hasTypeInErrorFields = _hasTypeInFields(entry.error.fields);
532
+
533
+ if (fields._hasTypeInSuccessFields !== true && entry.success && entry.success.fields)
534
+ fields._hasTypeInSuccessFields = _hasTypeInFields(entry.success.fields);
535
+
536
+ if (fields._hasTypeInInfoFields !== true && entry.info && entry.info.fields)
537
+ fields._hasTypeInInfoFields = _hasTypeInFields(entry.info.fields);
538
+
539
+ var content = templateCompareArticle(fields);
540
+ $root.after(content);
541
+ var $content = $root.next();
542
+
543
+ // Event on.click re-assign
544
+ $content.find('.versions li.version a').on('click', changeVersionCompareTo);
545
+
546
+ // select navigation
547
+ $('#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + currentVersion + '\']').addClass('has-modifications');
548
+
549
+ $root.remove();
550
+ // TODO: on change main version or select the highest version re-render
551
+ }
552
+
553
+ initDynamic();
554
+ }
555
+
556
+ /**
557
+ * Compare all currently selected Versions with their predecessor.
558
+ */
559
+ function changeAllVersionCompareTo(e) {
560
+ e.preventDefault();
561
+ $('article:visible .versions').each(function(){
562
+ var $root = $(this).parents('article');
563
+ var currentVersion = $root.data('version');
564
+ var $foundElement = null;
565
+ $(this).find('li.version a').each(function() {
566
+ var selectVersion = $(this).html();
567
+ if (selectVersion < currentVersion && ! $foundElement)
568
+ $foundElement = $(this);
569
+ });
570
+
571
+ if($foundElement)
572
+ $foundElement.trigger('click');
573
+ });
574
+ initDynamic();
575
+ }
576
+
577
+ /**
578
+ * Add article settings.
579
+ */
580
+ function addArticleSettings(fields, entry) {
581
+ // add unique id
582
+ // TODO: replace all group-name-version in template with id.
583
+ fields.id = fields.article.group + '-' + fields.article.name + '-' + fields.article.version;
584
+ fields.id = fields.id.replace(/\./g, '_');
585
+
586
+ if (entry.header && entry.header.fields)
587
+ fields._hasTypeInHeaderFields = _hasTypeInFields(entry.header.fields);
588
+
589
+ if (entry.parameter && entry.parameter.fields)
590
+ fields._hasTypeInParameterFields = _hasTypeInFields(entry.parameter.fields);
591
+
592
+ if (entry.error && entry.error.fields)
593
+ fields._hasTypeInErrorFields = _hasTypeInFields(entry.error.fields);
594
+
595
+ if (entry.success && entry.success.fields)
596
+ fields._hasTypeInSuccessFields = _hasTypeInFields(entry.success.fields);
597
+
598
+ if (entry.info && entry.info.fields)
599
+ fields._hasTypeInInfoFields = _hasTypeInFields(entry.info.fields);
600
+
601
+ // add template settings
602
+ fields.template = apiProject.template;
603
+ }
604
+
605
+ /**
606
+ * Render Article.
607
+ */
608
+ function renderArticle(group, name, version) {
609
+ var entry = {};
610
+ $.each(apiByGroupAndName[group][name], function(index, currentEntry) {
611
+ if (currentEntry.version === version)
612
+ entry = currentEntry;
613
+ });
614
+ var fields = {
615
+ article: entry,
616
+ versions: articleVersions[group][name]
617
+ };
618
+
619
+ addArticleSettings(fields, entry);
620
+
621
+ return templateArticle(fields);
622
+ }
623
+
624
+ /**
625
+ * Render original Article and remove the current visible Article.
626
+ */
627
+ function resetArticle(group, name, version) {
628
+ var $root = $('article[data-group=\'' + group + '\'][data-name=\'' + name + '\']:visible');
629
+ var content = renderArticle(group, name, version);
630
+
631
+ $root.after(content);
632
+ var $content = $root.next();
633
+
634
+ // Event on.click muss neu zugewiesen werden (sollte eigentlich mit on automatisch funktionieren... sollte)
635
+ $content.find('.versions li.version a').on('click', changeVersionCompareTo);
636
+
637
+ $('#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + version + '\']').removeClass('has-modifications');
638
+
639
+ $root.remove();
640
+ return;
641
+ }
642
+
643
+ /**
644
+ * Load google fonts.
645
+ */
646
+ function loadGoogleFontCss() {
647
+ var host = document.location.hostname.toLowerCase();
648
+ var protocol = document.location.protocol.toLowerCase();
649
+ var googleCss = '//fonts.googleapis.com/css?family=Source+Code+Pro|Source+Sans+Pro:400,600,700';
650
+ if (host == 'localhost' || !host.length || protocol === 'file:')
651
+ googleCss = 'http:' + googleCss;
652
+
653
+ $('<link/>', {
654
+ rel: 'stylesheet',
655
+ type: 'text/css',
656
+ href: googleCss
657
+ }).appendTo('head');
658
+ }
659
+
660
+ /**
661
+ * Return ordered entries by custom order and append not defined entries to the end.
662
+ * @param {String[]} elements
663
+ * @param {String[]} order
664
+ * @param {String} splitBy
665
+ * @return {String[]} Custom ordered list.
666
+ */
667
+ function sortByOrder(elements, order, splitBy) {
668
+ var results = [];
669
+ order.forEach (function(name) {
670
+ if (splitBy)
671
+ elements.forEach (function(element) {
672
+ var parts = element.split(splitBy);
673
+ var key = parts[1]; // reference keep for sorting
674
+ if (key == name)
675
+ results.push(element);
676
+ });
677
+ else
678
+ elements.forEach (function(key) {
679
+ if (key == name)
680
+ results.push(name);
681
+ });
682
+ });
683
+ // Append all other entries that ar not defined in order
684
+ elements.forEach(function(element) {
685
+ if (results.indexOf(element) === -1)
686
+ results.push(element);
687
+ });
688
+ return results;
689
+ }
690
+
691
+ });