Commit 6a60208e authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

PUT instead of POST for save all, sort when saving objs to webapp

parent 69e055f4
......@@ -188,10 +188,10 @@ def write_json(be, obj, mode):
file_path = os.path.join(resource_path, name + '.json')
if mode == WriteMode.UPDATE:
if os.path.isfile(file_path):
with open(file_path, 'w') as f:
f.write(stringified)
if mode == WriteMode.CREATE:
os.makedirs(folder_path, exist_ok=True)
with open(file_path, 'w') as f:
f.write(stringified)
elif mode == WriteMode.CREATE:
if not os.path.isfile(file_path):
os.makedirs(folder_path, exist_ok=True)
with open(file_path, 'w') as f:
......@@ -240,7 +240,7 @@ class Settings(Resource):
"""Returns the settings"""
return get_user_conf()
def post(self):
def put(self):
"""Overwrites the settings"""
new_conf = request.get_json()
with open('./user_conf.json', 'w') as f:
......@@ -280,8 +280,11 @@ def gen_beat_endpoint(entity):
def put(self):
"""Updates an already-existing object"""
obj = request.get_json()
write_json(self.be, obj, WriteMode.UPDATE)
obj_list = request.get_json()
if not isinstance(obj_list, list):
obj_list = [obj_list]
for obj in obj_list:
write_json(self.be, obj, WriteMode.UPDATE)
return self.refresh()
def delete(self):
......
......@@ -159,7 +159,7 @@ export class EntityDetail extends React.Component<Props, State> {
<TabPane tabId='1'>
<Row>
<Col>
<h4 style={{textAlign: 'center'}}>Under construction :)</h4>
<h4 style={{textAlign: 'center'}}>Under construction 😄</h4>
</Col>
</Row>
</TabPane>
......
......@@ -46,8 +46,8 @@ const saveAll = (allLists: Props) => {
[...BEAT_ENTITIES, 'settings']
//.filter(e => Array.isArray(allLists[e]))
.map(e => {
const post = genModuleApiFuncs(e).post;
return post(allLists[e]);
const put = genModuleApiFuncs(e).put;
return put(allLists[e]);
})
);
};
......
......@@ -29,7 +29,7 @@ export class Settings extends React.PureComponent<Props> {
}
save = async () => {
await genModuleApiFuncs('settings').post(this.props.settings);
await genModuleApiFuncs('settings').put(this.props.settings);
await this.props.fetchAllObjects();
}
......
......@@ -29,7 +29,7 @@ const initialState: State = {
}
};
const saveFunc = (state: BeatObject[], objs: BeatObject[]): BeatObject[] => [...objs];
const saveFunc = (state: BeatObject[], objs: BeatObject[]): BeatObject[] => [...objs].sort((a, b) => a.name > b.name ? 1 : -1);
const addFunc = (state: BeatObject[], obj: BeatObject): BeatObject[] => [obj, ...state];
const deleteFunc = (state: BeatObject[], obj: BeatObject): BeatObject[] => state.filter(o => o.name !== obj.name);
const updateFunc = (state: BeatObject[], { oldName, obj }): BeatObject[] => state.map(o => o.name === oldName ? obj : o);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment