admin_core 0.0.2 → 0.0.3

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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -1
  3. data/admin_core.gemspec +1 -1
  4. data/lib/admin_core.rb +34 -1
  5. data/lib/admin_core/errors.rb +6 -0
  6. data/lib/admin_core/resource_field_builder.rb +1 -11
  7. data/lib/admin_core/resource_filter/boolean.rb +2 -0
  8. data/lib/admin_core/resource_filter/number.rb +2 -0
  9. data/lib/admin_core/resource_filter/string.rb +2 -0
  10. data/lib/admin_core/resource_filter_builder.rb +1 -1
  11. data/lib/admin_core/version.rb +1 -1
  12. data/lib/generators/admin_core/resource_manager_generator.rb +4 -1
  13. data/lib/generators/admin_core/templates/admin-core.js +1047 -629
  14. metadata +2 -117
  15. data/client/.babelrc +0 -19
  16. data/client/.eslintignore +0 -3
  17. data/client/.eslintrc.yml +0 -20
  18. data/client/.flowconfig +0 -7
  19. data/client/.gitignore +0 -64
  20. data/client/.npmignore +0 -10
  21. data/client/README.md +0 -3
  22. data/client/admin-core.scss +0 -8
  23. data/client/flow-typed/npm/axios_v0.16.x.js +0 -120
  24. data/client/flow-typed/npm/classnames_v2.x.x.js +0 -16
  25. data/client/flow-typed/npm/lodash_v4.x.x.js +0 -514
  26. data/client/flow-typed/npm/react-router-dom_v4.x.x.js +0 -166
  27. data/client/flow-typed/npm/reactstrap_vx.x.x.js +0 -536
  28. data/client/package.json +0 -60
  29. data/client/src/.eslintrc.yml +0 -23
  30. data/client/src/AdminCore.jsx +0 -44
  31. data/client/src/components/Breadcrumb.jsx +0 -18
  32. data/client/src/components/Header.jsx +0 -45
  33. data/client/src/components/Pagination.jsx +0 -72
  34. data/client/src/components/ResourceFilters.jsx +0 -87
  35. data/client/src/components/ResourceForm.jsx +0 -103
  36. data/client/src/components/ResourcesCollection.jsx +0 -41
  37. data/client/src/components/Sidebar.jsx +0 -90
  38. data/client/src/decls.js +0 -119
  39. data/client/src/http-client.js +0 -18
  40. data/client/src/main.js +0 -9
  41. data/client/src/resource-field-renderer.js +0 -45
  42. data/client/src/resource-field/BelongsTo.jsx +0 -26
  43. data/client/src/resource-field/Boolean.jsx +0 -43
  44. data/client/src/resource-field/Date.jsx +0 -29
  45. data/client/src/resource-field/DateTime.jsx +0 -29
  46. data/client/src/resource-field/Enum.jsx +0 -34
  47. data/client/src/resource-field/Number.jsx +0 -28
  48. data/client/src/resource-field/String.jsx +0 -28
  49. data/client/src/resource-field/Text.jsx +0 -27
  50. data/client/src/resource-filter-renderer.js +0 -17
  51. data/client/src/resource-filter/Boolean.jsx +0 -22
  52. data/client/src/resource-filter/Number.jsx +0 -45
  53. data/client/src/resource-filter/String.jsx +0 -46
  54. data/client/src/resource-page/Base.js +0 -36
  55. data/client/src/resource-page/Edit.jsx +0 -48
  56. data/client/src/resource-page/Index.jsx +0 -141
  57. data/client/src/resource-page/New.jsx +0 -48
  58. data/client/src/resource-page/Show.jsx +0 -116
  59. data/client/webpack.config.js +0 -26
  60. data/client/yarn.lock +0 -3816
  61. data/sample/.gitignore +0 -21
  62. data/sample/Gemfile +0 -35
  63. data/sample/Gemfile.lock +0 -147
  64. data/sample/README.md +0 -24
  65. data/sample/Rakefile +0 -6
  66. data/sample/app/assets/config/manifest.js +0 -2
  67. data/sample/app/assets/images/.keep +0 -0
  68. data/sample/app/assets/stylesheets/application.css +0 -15
  69. data/sample/app/controllers/admin/application_controller.rb +0 -4
  70. data/sample/app/controllers/admin/tweets_controller.rb +0 -4
  71. data/sample/app/controllers/admin/users_controller.rb +0 -4
  72. data/sample/app/controllers/application_controller.rb +0 -3
  73. data/sample/app/controllers/concerns/.keep +0 -0
  74. data/sample/app/helpers/application_helper.rb +0 -2
  75. data/sample/app/jobs/application_job.rb +0 -2
  76. data/sample/app/models/admin/tweet.rb +0 -35
  77. data/sample/app/models/admin/user.rb +0 -41
  78. data/sample/app/models/application_record.rb +0 -3
  79. data/sample/app/models/concerns/.keep +0 -0
  80. data/sample/app/models/tweet.rb +0 -3
  81. data/sample/app/models/user.rb +0 -3
  82. data/sample/app/views/admin/application.html.erb +0 -64
  83. data/sample/app/views/layouts/application.html.erb +0 -13
  84. data/sample/bin/bundle +0 -3
  85. data/sample/bin/rails +0 -4
  86. data/sample/bin/rake +0 -4
  87. data/sample/bin/setup +0 -34
  88. data/sample/bin/update +0 -29
  89. data/sample/config.ru +0 -5
  90. data/sample/config/application.rb +0 -25
  91. data/sample/config/boot.rb +0 -3
  92. data/sample/config/database.yml +0 -25
  93. data/sample/config/environment.rb +0 -5
  94. data/sample/config/environments/development.rb +0 -42
  95. data/sample/config/environments/production.rb +0 -69
  96. data/sample/config/environments/test.rb +0 -36
  97. data/sample/config/initializers/admin_core.rb +0 -8
  98. data/sample/config/initializers/application_controller_renderer.rb +0 -6
  99. data/sample/config/initializers/backtrace_silencers.rb +0 -7
  100. data/sample/config/initializers/cookies_serializer.rb +0 -5
  101. data/sample/config/initializers/filter_parameter_logging.rb +0 -4
  102. data/sample/config/initializers/inflections.rb +0 -16
  103. data/sample/config/initializers/mime_types.rb +0 -4
  104. data/sample/config/initializers/new_framework_defaults.rb +0 -24
  105. data/sample/config/initializers/session_store.rb +0 -3
  106. data/sample/config/initializers/wrap_parameters.rb +0 -14
  107. data/sample/config/locales/en.yml +0 -23
  108. data/sample/config/routes.rb +0 -6
  109. data/sample/config/secrets.yml +0 -22
  110. data/sample/db/migrate/20170417055257_create_users.rb +0 -10
  111. data/sample/db/migrate/20170417055412_create_tweets.rb +0 -9
  112. data/sample/db/schema.rb +0 -31
  113. data/sample/db/seeds.rb +0 -7
  114. data/sample/lib/assets/.keep +0 -0
  115. data/sample/lib/tasks/.keep +0 -0
  116. data/sample/log/.keep +0 -0
  117. data/sample/public/404.html +0 -67
  118. data/sample/public/422.html +0 -67
  119. data/sample/public/500.html +0 -66
  120. data/sample/public/apple-touch-icon-precomposed.png +0 -0
  121. data/sample/public/apple-touch-icon.png +0 -0
  122. data/sample/public/bundle.min.js +0 -27
  123. data/sample/public/bundle.min.js.map +0 -1
  124. data/sample/public/favicon.ico +0 -0
  125. data/sample/public/javascripts/admin-core.js +0 -38196
  126. data/sample/public/robots.txt +0 -5
  127. data/sample/public/stylesheets/admin-core.css +0 -1
  128. data/sample/tmp/.keep +0 -0
  129. data/sample/vendor/assets/stylesheets/.keep +0 -0
@@ -1,41 +0,0 @@
1
- // @flow
2
- import React from "react";
3
- import {Link} from "react-router-dom";
4
-
5
- import type {Resource} from "../decls";
6
- import {renderIndex} from "../resource-field-renderer";
7
-
8
- export default class ResourcesCollection extends React.Component {
9
- props: {
10
- attributes: string[];
11
- resources: Resource[];
12
- }
13
-
14
- render() {
15
- return (
16
- <table className="table table-bordered table-hover table-sm">
17
- <thead>
18
- <tr>
19
- {this.props.attributes.map((attribute, i) =>
20
- <th key={i}>{attribute}</th>
21
- )}
22
- </tr>
23
- </thead>
24
- <tbody>
25
- {this.props.resources.map((resource, i) =>
26
- <tr key={i}>
27
- {resource.fields.map((field, j) => {
28
- const showPath = resource.showPath;
29
- if (j === 0 && showPath) {
30
- return <td key={j}><Link to={showPath}>{renderIndex(field)}</Link></td>;
31
- } else {
32
- return <td key={j}>{renderIndex(field)}</td>;
33
- }
34
- })}
35
- </tr>
36
- )}
37
- </tbody>
38
- </table>
39
- );
40
- }
41
- }
@@ -1,90 +0,0 @@
1
- // @flow
2
- import React from "react";
3
- import {NavLink} from "react-router-dom";
4
-
5
- import type {
6
- SidebarDropdown,
7
- SidebarItem,
8
- SidebarLink,
9
- SidebarTitle,
10
- } from "../decls";
11
-
12
- export default class Sidebar extends React.Component {
13
- props: {
14
- items: SidebarItem[];
15
- }
16
-
17
- handleClick(e: SyntheticEvent) {
18
- e.preventDefault();
19
- const target = e.target;
20
- if (target instanceof HTMLElement) {
21
- const parent = target.parentElement;
22
- if (parent) {
23
- parent.classList.toggle("open");
24
- }
25
- }
26
- }
27
-
28
- renderSidebarItem(item: SidebarItem, key: number) {
29
- if (item.type === 'title') {
30
- return this.renderSidebarTitle(item, key);
31
- } else if (item.type === 'link') {
32
- return this.renderSidebarLink(item, key);
33
- } else if (item.type === 'dropdown') {
34
- return this.renderSidebarDropdown(item, key);
35
- }
36
- }
37
-
38
- renderSidebarTitle(sidebarTitle: SidebarTitle, key: number) {
39
- return (
40
- <li className="nav-title" key={key}>
41
- {sidebarTitle.displayName}
42
- </li>
43
- );
44
- }
45
-
46
- renderSidebarDropdown(sidebarDropdown: SidebarDropdown, key: number) {
47
- return (
48
- <li className="nav-item nav-dropdown" key={key}>
49
- <a className="nav-link nav-dropdown-toggle" href="#" onClick={this.handleClick}>
50
- {sidebarDropdown.displayName}
51
- </a>
52
- <ul className="nav-dropdown-items">
53
- {sidebarDropdown.links.map((link, i) =>
54
- this.renderSidebarLink(link, i)
55
- )}
56
- </ul>
57
- </li>
58
- )
59
- }
60
-
61
- renderSidebarLink(link: SidebarLink, key: number) {
62
- return (
63
- <li className="nav-item" key={key}>
64
- {link.external ?
65
- <a href={link.link} className="nav-link">
66
- {link.displayName}
67
- </a>
68
- :
69
- <NavLink to={link.link} className="nav-link" activeClassName="active">
70
- {link.displayName}
71
- </NavLink>
72
- }
73
- </li>
74
- );
75
- }
76
-
77
- render() {
78
- return (
79
- <div className="sidebar">
80
- <nav className="sidebar-nav">
81
- <ul className="nav">
82
- {this.props.items.map((item, i) =>
83
- this.renderSidebarItem(item, i)
84
- )}
85
- </ul>
86
- </nav>
87
- </div>
88
- );
89
- }
90
- }
@@ -1,119 +0,0 @@
1
- // @flow
2
-
3
- // Represent a single ActiveRecord::Base
4
- export type Resource = {
5
- displayName: string;
6
- name: string;
7
- showPath: ?string; // If it is null, the resource is not persisted.
8
- editPath: ?string; // If it is null, the resource is not updatable.
9
- destroyable: boolean;
10
- fields: ResourceField[];
11
- }
12
-
13
- // Represent a child class of AdminCore::BaseResourceManager.
14
- //
15
- // @see AdminCore::BaseResourceManager.to_hash
16
- export type ResourceManager = {
17
- displayName: string;
18
- indexPath: string;
19
- newPath: ?string; // If it is null, the resource is not creatable.
20
- showPath: string;
21
- editPath: ?string; // If it is null, the resource is not updatable.
22
- scopes: string[];
23
- }
24
-
25
- type $ResourceField<T, V> = {
26
- displayName: string;
27
- name: string;
28
- type: T;
29
- value: V;
30
- };
31
-
32
- export type ResourceField = $ResourceField<*, *>;
33
-
34
- export type ResourceField$Boolean = $ResourceField<"boolean", boolean>;
35
- export type ResourceField$BelongsTo = $ResourceField<"belongs_to", { resource: Resource; paramName: string; }>;
36
- export type ResourceField$Date = $ResourceField<"date", string>;
37
- export type ResourceField$DateTime = $ResourceField<"date_time", string>;
38
- export type ResourceField$Enum = $ResourceField<"enum", { value: string; values: string[]; }>;
39
- export type ResourceField$Number = $ResourceField<"number", number>;
40
- export type ResourceField$String = $ResourceField<"string", string>;
41
- export type ResourceField$Text = $ResourceField<"text", string>;
42
-
43
- // Shape of exports of resource-field/*.js
44
- export type ResourceFieldModule = {
45
- Index: (ResourceField) => React$Element<*>;
46
- New: (ResourceField, onChange: (string, any) => void) => React$Element<*>;
47
- Show: (ResourceField) => React$Element<*>;
48
- Edit: (ResourceField, onChange: (string, any) => void) => React$Element<*>;
49
- getValue: (ResourceField) => any;
50
- }
51
-
52
-
53
- type $ResourceFilter<O, V> = {
54
- type: string;
55
- name: string;
56
- displayName: string;
57
- query: {
58
- operator: O;
59
- value: ?V;
60
- };
61
- }
62
-
63
- export type ResourceFilter = $ResourceFilter<*, *>;
64
-
65
- export type ResourceFilter$Boolean = $ResourceFilter<"is", boolean>;
66
- export type ResourceFilter$Number = $ResourceFilter<"equals" | "greater_than" | "less_than", number>;
67
- export type ResourceFilter$String = $ResourceFilter<"contains" | "equals" | "starts_with" | "ends_with", string>;
68
-
69
- // Shpae of exports of admin-core/resource-filter/*.js
70
- export type ResourceFilterModule = {
71
- Filter: (ResourceFilter, _: (string, string, string) => void) => React$Element<*>;
72
- }
73
-
74
- // Shape of AdminCore::ResourcePage::Index#to_json
75
- export type ResourcePage$Index = {
76
- attributes: string[];
77
- resources: Resource[];
78
- filters: ResourceFilter[];
79
- scopes: { name: string; count: number; }[];
80
- pagination: {
81
- current: number;
82
- total: number;
83
- };
84
- }
85
-
86
- // Shape of AdminCore::ResourcePage::New#to_json
87
- export type ResourcePage$New = {
88
- resource: Resource;
89
- }
90
-
91
- // Shape of AdminCore::ResourcePage::Show#to_json
92
- export type ResourcePage$Show = {
93
- resource: Resource;
94
- }
95
-
96
- // Shape of AdminCore::ResourcePage::Edit#to_json
97
- export type ResourcePage$Edit = {
98
- resource: Resource;
99
- }
100
-
101
- export type SidebarItem = SidebarTitle | SidebarDropdown | SidebarLink;
102
-
103
- export type SidebarTitle = {
104
- type: "title";
105
- displayName: string;
106
- }
107
-
108
- export type SidebarDropdown = {
109
- type: "dropdown";
110
- displayName: string;
111
- links: SidebarLink[];
112
- }
113
-
114
- export type SidebarLink = {
115
- type: "link";
116
- displayName: string;
117
- link: string;
118
- external: boolean;
119
- };
@@ -1,18 +0,0 @@
1
- // @flow
2
- import axios from "axios";
3
-
4
- const httpClient = axios.create({
5
- headers: {
6
- "Accept": "application/json",
7
- },
8
- });
9
-
10
- httpClient.interceptors.request.use(config => {
11
- const csrfToken = document.querySelector("meta[name='csrf-token']");
12
- if (csrfToken instanceof HTMLMetaElement && config.headers) {
13
- config.headers["X-CSRF-Token"] = csrfToken.content;
14
- }
15
- return config;
16
- });
17
-
18
- export default httpClient;
@@ -1,9 +0,0 @@
1
- import AdminCore from "./AdminCore";
2
- import React from "react";
3
- import ReactDOM from "react-dom";
4
- import ReactRouterDOM from "react-router-dom";
5
-
6
- global.AdminCore = AdminCore;
7
- global.React = React;
8
- global.ReactDOM = ReactDOM;
9
- global.ReactRouterDOM = ReactRouterDOM;
@@ -1,45 +0,0 @@
1
- // @flow
2
- import type {
3
- ResourceFieldModule,
4
- ResourceField,
5
- } from "./decls";
6
-
7
- const resourceFields: { [string]: ResourceFieldModule; } = {};
8
-
9
- export function register(name: string, module: ResourceFieldModule) {
10
- resourceFields[name] = module;
11
- }
12
-
13
- export function getValue(field: ResourceField) {
14
- const module = resourceFields[field.type];
15
- return module.getValue(field);
16
- }
17
-
18
- export function renderIndex(field: ResourceField) {
19
- const module = resourceFields[field.type];
20
- return module.Index(field);
21
- }
22
-
23
- export function renderNew(field: ResourceField, onChange: (string, any) => void) {
24
- const module = resourceFields[field.type];
25
- return module.New(field, onChange);
26
- }
27
-
28
- export function renderShow(field: ResourceField) {
29
- const module = resourceFields[field.type];
30
- return module.Show(field);
31
- }
32
-
33
- export function renderEdit(field: ResourceField, onChange: (string, any) => void) {
34
- const module = resourceFields[field.type];
35
- return module.Edit(field, onChange);
36
- }
37
-
38
- register("belongs_to", require("./resource-field/BelongsTo"));
39
- register("boolean", require("./resource-field/Boolean"));
40
- register("date", require("./resource-field/Date"));
41
- register("date_time", require("./resource-field/DateTime"));
42
- register("enum", require("./resource-field/Enum"));
43
- register("number", require("./resource-field/Number"));
44
- register("string", require("./resource-field/String"));
45
- register("text", require("./resource-field/Text"));
@@ -1,26 +0,0 @@
1
- // @flow
2
- import React from "react";
3
- import {Link} from "react-router-dom";
4
-
5
- import type {ResourceField$BelongsTo} from "../decls";
6
- import {getValue} from "../resource-field-renderer";
7
-
8
- exports.getValue = function (field: ResourceField$BelongsTo) {
9
- const fi = field.value.resource.fields.find(f => f.name === field.value.paramName);
10
- if (fi) {
11
- return getValue(fi);
12
- }
13
- };
14
-
15
- exports.Index = exports.Show = function (field: ResourceField$BelongsTo) {
16
- const resource = field.value.resource;
17
- if (resource.showPath) {
18
- return <Link to={resource.showPath}>{resource.displayName}</Link>;
19
- } else {
20
- return <span>{resource.displayName}</span>;
21
- }
22
- };
23
-
24
- exports.New = exports.Edit = function(_field: ResourceField$BelongsTo, _onChange: (string, any) => void) {
25
- throw new Error("Not implemented");
26
- };
@@ -1,43 +0,0 @@
1
- // @flow
2
- import React from "react";
3
- import type {ResourceField$Boolean} from "../decls";
4
-
5
- exports.getValue = function (field: ResourceField$Boolean) {
6
- return field.value;
7
- };
8
-
9
- exports.Index = exports.Show = function (field: ResourceField$Boolean) {
10
- return (
11
- <span className="switch switch-text switch-primary">
12
- <input
13
- checked={field.value}
14
- className="switch-input"
15
- disabled={true}
16
- type="checkbox"
17
- />
18
- <span className="switch-label" data-on="On" data-off="Off"/>
19
- <span className="switch-handle"/>
20
- </span>
21
- );
22
- };
23
-
24
- exports.New = exports.Edit = function (field: ResourceField$Boolean, onChange: (string, any) => void) {
25
- return (
26
- <label className="switch switch-text switch-primary">
27
- <input
28
- type="checkbox"
29
- name={field.name}
30
- className="switch-input"
31
- defaultChecked={field.value}
32
- onChange={(e: SyntheticEvent) => {
33
- const el = e.target;
34
- if (el instanceof HTMLInputElement) {
35
- onChange(field.name, el.checked);
36
- }
37
- }}
38
- />
39
- <span className="switch-label" data-on="On" data-off="Off"/>
40
- <span className="switch-handle"/>
41
- </label>
42
- );
43
- };
@@ -1,29 +0,0 @@
1
- // @flow
2
- import React from "react";
3
- import type {ResourceField$Date} from "../decls";
4
-
5
- exports.getValue = function (field: ResourceField$Date) {
6
- return field.value;
7
- };
8
-
9
- exports.Index = exports.Show = function (field: ResourceField$Date) {
10
- const date = new Date(field.value);
11
- return <span>{date.toLocaleDateString()}</span>;
12
- };
13
-
14
- exports.New = exports.Edit = function (field: ResourceField$Date, onChange: (string, any) => void) {
15
- return (
16
- <input
17
- className="form-control"
18
- defaultValue={field.value}
19
- name={field.name}
20
- onChange={(e: SyntheticEvent) => {
21
- const el = e.target;
22
- if (el instanceof HTMLInputElement) {
23
- onChange(field.name, el.value);
24
- }
25
- }}
26
- type="date"
27
- />
28
- );
29
- };
@@ -1,29 +0,0 @@
1
- // @flow
2
- import React from "react";
3
- import type {ResourceField$DateTime} from "../decls";
4
-
5
- exports.getValue = function (field: ResourceField$DateTime) {
6
- return field.value;
7
- };
8
-
9
- exports.Index = exports.Show = function (field: ResourceField$DateTime) {
10
- const date = new Date(field.value);
11
- return <span>{date.toLocaleString()}</span>;
12
- };
13
-
14
- exports.New = exports.Edit = function (field: ResourceField$DateTime, onChange: (string, any) => void) {
15
- return (
16
- <input
17
- className="form-control"
18
- defaultValue={field.value}
19
- name={field.name}
20
- onChange={(e: SyntheticEvent) => {
21
- const el = e.target;
22
- if (el instanceof HTMLInputElement) {
23
- onChange(field.name, el.value);
24
- }
25
- }}
26
- type="datetime"
27
- />
28
- );
29
- };