Skip to content

Commit f552bb8

Browse files
author
Sean Bethel
committed
syntax updates
1 parent f26ebf6 commit f552bb8

File tree

9 files changed

+58
-31
lines changed

9 files changed

+58
-31
lines changed

src/assets/src/Reducer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { Component } from 'react';
22
import ReactDOM from 'react-dom';
33
import ReactSync from './ReactSync';
44
import { Model, Page } from './components';
5+
6+
import { snake_case, studly_case } from './helpers';
57
// import * as pages from 'pages';
68

79
// import * as models from 'models';
@@ -14,17 +16,19 @@ export default function Reducer(){
1416
const models = Model.models;
1517

1618
const pages = Page.pages;
17-
19+
1820
const ReactSyncInstance = new ReactSync;
19-
21+
2022
ReactSyncInstance.boot({pages: pages});
21-
23+
2224
const { state = {} } = ReactSyncInstance.page_data;
2325

2426
if(_.isEmpty(state)) return null;
2527

2628
const model_map = Object.values(models).reduce((accumulator, v) => {
2729
accumulator[v.plural] = v;
30+
accumulator[snake_case(v.plural)] = v;
31+
accumulator[studly_case(v.plural)] = v;
2832
return accumulator;
2933
}, {});
3034
const models_with_keys = Object.values(models).map(C => [C.plural, C]);

src/assets/src/components/Field.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Field extends Component{
1212

1313
this.field_type = Field.field_type.bind(this.props.model);
1414

15-
this.label = this.props.label || this.props.property;
15+
this.label = (this.props.label === false) ? false : (this.props.label || this.props.property);
1616
}
1717

1818
/** */
@@ -91,6 +91,9 @@ class Field extends Component{
9191
}
9292
if(!field_renders[type.field]) return null;
9393
const classes = (this.props.className || '') + ' form-group';
94+
if(this.label === false){
95+
return field_renders[type.field];
96+
}
9497
return <fieldset className={classes}><label htmlFor={rand}>{this.label}</label> {field_renders[type.field]}</fieldset>;
9598
}
9699

src/assets/src/components/Model.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ class Model extends Component{
9797
}
9898
}
9999
if(relationValueModels){
100-
this[relationName] = relationValueModels;
100+
//this[relationName] = relationValueModels;
101+
def(this, relationName, () => relationValueModels);
102+
def(this.relations, relationName, () => relationValueModels);
101103
}
102-
103-
// this.relations[relationName] = this[relationName];
104104

105105
}
106106
else {
@@ -111,27 +111,12 @@ class Model extends Component{
111111
else{
112112
def(this, relationName, () => this[relation_type](definition));
113113
def(this.relations, relationName, () => this[relation_type](definition));
114-
/*
115-
const resolved = this[relation_type](definition);
116-
this[relationName] = resolved;
117-
this.relations[relationName] = resolved;
118-
*/
119114
}
120115
}
121116
});
122117

123118
this.constructor.boot(this);
124-
125-
/*
126-
for(const i in this.props){
127-
if(i in this){
128-
console.log(i + ' is alrady set');
129-
}
130-
else{
131-
console.log(i);
132-
}
133-
}
134-
*/
119+
135120
}
136121

137122
/** */

src/assets/src/components/Shell.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class Shell extends Component{
2424

2525
/** */
2626
refresh(){
27-
let { Model, url } = this.props;
27+
let { url } = this.props;
28+
/*
2829
let fromcache;
2930
// this.setState({children: null});
3031
if(!this.constructor.cached[url]){
@@ -34,6 +35,8 @@ class Shell extends Component{
3435
this.constructor.cached[url] = axios.get(url);
3536
}
3637
this.constructor.cached[url].then(response => {
38+
*/
39+
axios.get(url).then(response => {
3740
this.setState({children: response.data});
3841
}).catch((err) => {
3942
console.log(err, err.response);
@@ -54,8 +57,9 @@ class Shell extends Component{
5457
this.refresh();
5558
}
5659
else if(!this.constructor.cached[this.props.url]){
57-
this.refresh();
60+
// this.refresh();
5861
}
62+
// else this.refresh();
5963
}
6064

6165
/** */
@@ -88,7 +92,10 @@ class Shell extends Component{
8892
return (
8993
<>{items.map((props, i) => {
9094
const normal_props = Model.get_non_reserved_props(remainder);
91-
return <Model key={i} {...normal_props} {...props} shell={this} refresh={this.refresh.bind(this)} />;
95+
const kname = Model.getPrimaryKey();
96+
// debugger
97+
const k = Model.make_key(props[kname], 'shell');
98+
return <Model key={k} {...normal_props} {...props} shell={this} refresh={this.refresh.bind(this)} />;
9299
})}
93100
</>
94101
);

src/assets/src/components/traits/Eloquent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Eloquent extends Trait{
100100
}
101101

102102
const qs_string = qs.stringify(qs_object);
103+
103104
return map[q] + `?${qs_string}`;
104105
}
105106

@@ -118,7 +119,7 @@ class Eloquent extends Trait{
118119
let renderAs = this.props.renderAs || this.props.render || 'Default';
119120
let renderName = `render${studly_case(renderAs)}`;
120121
if(typeof renderAs === 'function'){
121-
return renderAs(this.props);
122+
return renderAs(this.props, this);
122123
}
123124

124125
if(typeof this[renderName] === 'function'){

src/assets/src/components/traits/HasKeyProp.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class HasKeyProp extends Trait{
1212
super(targetClass);
1313
}
1414

15+
/** */
16+
static make_key(id, prefix = ''){
17+
return `${prefix}_${this.plural}_${id}`;
18+
}
19+
20+
1521
/** */
1622
unique_key(prefix = ''){
1723
return `${prefix}_${this.plural}_${this.id}`;

src/assets/src/components/traits/HasRelations.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ class HasRelations extends Trait{
1818
constructor(targetClass){
1919
super(targetClass);
2020
}
21+
22+
23+
getRelation(relation_name){
24+
const { definition } = this.schema[relation_name];
25+
const { related, foreignKey } = definition;
26+
const retval = { ...definition };
27+
retval.RelatedModel = Model.getModel(related);
28+
retval.render = (renderTypeOrFn = "default") => {
29+
if(!this.props[foreignKey]) return null;
30+
return <retval.RelatedModel find={this.props[foreignKey]} render={renderTypeOrFn} />
31+
};
32+
return retval;
33+
}
34+
2135

2236
/** */
2337
HasMany(relationship_definition_from_schema){
@@ -95,7 +109,7 @@ withDefault: null
95109
return
96110
}
97111
*/
98-
console.log('BelongsTo found_item', Class_, found_item, found_item instanceof Model);
112+
// console.log('BelongsTo found_item', Class_, found_item, found_item instanceof Model);
99113
return <Class_ {...app_get(`${plural}.${related_id}`)}/>
100114

101115
}

src/assets/src/components/traits/Queryable.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Queryable extends Trait{
3939
*/
4040
static find(id){
4141
const { plural, repo } = this;
42-
const dotstring = `${plural}.${id}`;
42+
const dotstring = `${plural}.${id}`;
4343
return app_get(dotstring);
4444
}
4545

@@ -190,14 +190,20 @@ class Queryable extends Trait{
190190

191191
/** */
192192
static refresh_static(){
193+
Shell.cache = {};
193194
ReactSync.getInstance().update();
194195
}
195196

196197

197198
/** */
198-
refresh(redirectEndpoint){
199+
refresh(){
199200
Shell.cache = {};
200-
ReactSync.getInstance().update();
201+
202+
if(this.props.refresh) this.props.refresh()
203+
else{
204+
ReactSync.getInstance().update();
205+
}
206+
201207
}
202208

203209
}

src/helpers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function get_schema($model = null){
130130
$relations = collect($reflection->getMethods())->filter(function($v) use($model_name, $reflected_relations){
131131
if($v->class == $model_name){
132132
$function_text = returnFunctionText($v);
133+
133134
$isrel = !!$reflected_relations->first(function($m) use($function_text){
134135
return str_contains($function_text, '->' . $m);
135136
});

0 commit comments

Comments
 (0)