ember-tribe 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  TRIBE_API_URL=""
2
- TRIBE_API_TOKEN=""
2
+ TRIBE_API_KEY=""
@@ -5,8 +5,11 @@ import { underscore } from '@ember/string';
5
5
  export default class ApplicationAdapter extends JSONAPIAdapter {
6
6
  host = ENV.TribeENV.API_URL;
7
7
  namespace = 'api.php';
8
+ headers = {
9
+ Authorization: `Bearer ${ENV.TribeENV.API_KEY}`,
10
+ };
8
11
 
9
12
  pathForType(type) {
10
13
  return underscore(type);
11
14
  }
12
- }
15
+ }
@@ -0,0 +1,6 @@
1
+ import Model, { attr } from '@ember-data/model';
2
+
3
+ export default class WebappModel extends Model {
4
+ @attr slug;
5
+ @attr modules;
6
+ }
@@ -3,11 +3,9 @@ import * as bootstrap from 'bootstrap';
3
3
  import { service } from '@ember/service';
4
4
 
5
5
  export default class ApplicationRoute extends Route {
6
- /*
7
6
  @service types;
8
7
 
9
8
  async beforeModel() {
10
9
  await this.types.fetchAgain();
11
10
  }
12
- */
13
11
  }
@@ -1,7 +1,10 @@
1
1
  import Service from '@ember/service';
2
+ import ENV from '<%= dasherizedPackageName %>/config/environment';
2
3
  import { service } from '@ember/service';
3
4
  import { action } from '@ember/object';
4
5
  import { tracked } from '@glimmer/tracking';
6
+ import Model, { attr } from '@ember-data/model';
7
+ import { getOwner } from '@ember/application';
5
8
 
6
9
  export default class TypesService extends Service {
7
10
  @service store;
@@ -11,9 +14,27 @@ export default class TypesService extends Service {
11
14
 
12
15
  @action
13
16
  async fetchAgain() {
14
- this.json = await this.store.findRecord('webapp', 0, {
15
- include: ['total_objects'],
16
- });
17
- this.json = this.json;
17
+ if (ENV.TribeENV.API_URL !== undefined && ENV.TribeENV.API_URL != '') {
18
+ this.json = await this.store.findRecord('webapp', 0, {});
19
+ let owner = getOwner(this);
20
+
21
+ Object.entries(this.json.modules).forEach(([modelName, modelData]) => {
22
+ const modelDynamicName = modelName.replace(/_/g, '-');
23
+
24
+ class DynamicModel extends Model {
25
+ @attr slug;
26
+ @attr modules;
27
+ }
28
+
29
+ if (!owner.hasRegistration(`model:${modelDynamicName}`)) {
30
+ owner.register(`model:${modelDynamicName}`, DynamicModel);
31
+ }
32
+ });
33
+
34
+ this.json = await this.store.findRecord('webapp', 0, {
35
+ include: ['total_objects'],
36
+ });
37
+ this.json = this.json;
38
+ }
18
39
  }
19
40
  }
@@ -2,13 +2,12 @@
2
2
 
3
3
  module.exports = function (/* environment, appConfig */) {
4
4
  let ENV = {
5
-
6
5
  //Wildfire Tribe config for EmberJS
7
6
  TribeENV: {
8
7
  API_URL: process.env.TRIBE_API_URL,
8
+ API_KEY: process.env.TRIBE_API_KEY,
9
9
  },
10
-
11
10
  };
12
11
 
13
12
  return ENV;
14
- };
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-tribe",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "The default blueprint for using Tribe within EmberJS.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -1,23 +0,0 @@
1
- <?php
2
- $_ENV = parse_ini_file('.env');
3
- if (($_ENV['TRIBE_API_URL'] ?? false) && $_ENV['TRIBE_API_URL'] != '') {
4
- $types = json_decode(file_get_contents($_ENV['TRIBE_API_URL'].'/api.php/webapp/0'), true)['data']['attributes']['modules'];
5
- } else {
6
- $types = json_decode(file_get_contents('https://raw.githubusercontent.com/tribe-framework/types.json/master/blueprints/junction-init.json'), true);
7
- }
8
-
9
- // re-create models folder
10
- $commands = "[ -d app/models ] && rm -r app/models && mkdir app/models; ";
11
- // remove test for models
12
- $commands .= "[ -d tests/unit/models ] && rm -r tests/unit/models; ";
13
-
14
- foreach (array_keys($types) as $type) {
15
- if ($type == 'webapp' || in_array($type, ($types['webapp']['interface_urls'][basename(dirname(__FILE__))]['types'] ?? array_keys($types)))) {
16
-
17
- $type_hyphen = str_replace('_', '-', $type);
18
- $type_ucwords = str_replace(' ', '', ucwords(str_replace('_', ' ', $type)));
19
- $commands .= "echo \"import Model, { attr } from '@ember-data/model';\n\nexport default class ".$type_ucwords."Model extends Model {\n @attr slug;\n @attr modules;\n}\" > app/models/".$type_hyphen.".js; ";
20
- }
21
- }
22
-
23
- exec($commands);