Browse Source

tweaked launch conf to always launche at the same port && fixed controller.create

master
TheNils 1 month ago
parent
commit
b02cd8b132
11 changed files with 73 additions and 107 deletions
  1. +15
    -0
      .vscode/launch.json
  2. +2
    -0
      README.md
  3. +8
    -10
      lib/api/api.dart
  4. +10
    -3
      lib/api/schema.dart
  5. +1
    -0
      lib/lang/en.dart
  6. +1
    -0
      lib/lang/fr.dart
  7. +0
    -80
      lib/store/projects.dart
  8. +6
    -7
      lib/store/user.dart
  9. +1
    -1
      lib/views/account.dart
  10. +17
    -5
      lib/views/accountForm.dart
  11. +12
    -1
      workspace.code-workspace

+ 15
- 0
.vscode/launch.json View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
"args": ["-d", "chrome","--web-port", "8085"],
}
]
}

+ 2
- 0
README.md View File

@ -1,5 +1,7 @@
# youtribe_lib
run this project with `flutter -v run -d *chrome* --web-port=28080`
## Structure
`@/views/` for app screens and components


+ 8
- 10
lib/api/api.dart View File

@ -66,16 +66,14 @@ class Api {
await refreshJwt();
var res = client.post('${globals.apiUrl}$path',
headers: this.apiHeaders, body: body);
headers: this.apiHeaders, body: jsonEncode(body));
return await handleResponse(res, path, body, tryCount, post);
}
Future<Map<dynamic, dynamic>> patch(String path, Map<dynamic, dynamic> body,
[int tryCount = 1]) async {
print("api patch");
await refreshJwt();
print("api after jwt");
var res = client.patch('${globals.apiUrl}$path',
headers: this.apiHeaders, body: jsonEncode(body));
return await handleResponse(res, path, body, tryCount, patch);
@ -92,14 +90,14 @@ class Api {
return await handleResponse(res, path, body, tryCount, get);
}
Future<Map<dynamic, dynamic>> put(String path, Map<dynamic, dynamic> body,
[int tryCount = 1]) async {
await refreshJwt();
// Future<Map<dynamic, dynamic>> put(String path, Map<dynamic, dynamic> body,
// [int tryCount = 1]) async {
// await refreshJwt();
var res = client.put('${globals.apiUrl}$path',
headers: this.apiHeaders, body: body);
return await handleResponse(res, path, body, tryCount, put);
}
// var res = client.put('${globals.apiUrl}$path',
// headers: this.apiHeaders, body: body);
// return await handleResponse(res, path, body, tryCount, put);
// }
Future<Map<dynamic, dynamic>> delete(String path,
[Map<dynamic, dynamic> body = const {}, int tryCount = 1]) async {


+ 10
- 3
lib/api/schema.dart View File

@ -1,4 +1,4 @@
Map<dynamic, dynamic> schema = {
Map<dynamic, dynamic> userSchema = {
"projects": {
"project_id": {
"collection": "project",
@ -24,8 +24,15 @@ Map<dynamic, dynamic> schema = {
"project_id": {
"collection": "project",
"kind": "M2M",
"customers": {"collection": "directus_users", "kind": "M2M"},
//"agencies": {"collection": "agency", "kind": "M2M"},
"customers": {
"directus_users_id": {"collection": "directus_users", "kind": "M2M"}
},
"agencies": {
"agency_id": {
"collection": "agency",
"kind": "M2M",
},
},
"steps": {
"collection": "steps",
"kind": "O2M",


+ 1
- 0
lib/lang/en.dart View File

@ -7,4 +7,5 @@ Map<String, String> en = {
'edit': 'Edit',
'save': 'Save',
'first-name': 'First name',
'test-create': 'create a report in a step',
};

+ 1
- 0
lib/lang/fr.dart View File

@ -7,4 +7,5 @@ Map<String, String> fr = {
'edit': 'Modifier',
'save': 'Sauvegarder',
'first-name': 'Prénom',
'test-create': 'creer un rapport dans un compte rendu',
};

+ 0
- 80
lib/store/projects.dart View File

@ -1,80 +0,0 @@
import 'dart:convert';
import 'dart:developer';
import 'package:get/state_manager.dart';
import 'package:youtribe_lib/api/api.dart';
import 'package:localstorage/localstorage.dart';
class Projects extends GetxController {
final _collection = 'project';
final _fields = '''
project.*,
project.agencies.agency_id,
project.customers.customer_id,
'''
.trim()
.replaceAll(" ", "");
var _filters = "";
final _api = Api();
final _items = Rx<List<dynamic>>().obs;
final isLoading = false.obs;
var _localStorage;
get items => _items().value;
set items(payload) {
_items(Rx(payload));
_localStorage.setItem(_collection, jsonEncode(items));
}
@override
void onInit() async {
_localStorage = new LocalStorage('$_collection-store');
await _localStorage.ready;
var localItems = await _localStorage.getItem('items');
if (localItems != null) {
items = jsonDecode(localItems);
fetch();
}
super.onInit();
}
Future<bool> fetch() async {
var res = await _api.get('/$_collection?$_fields&$_filters');
if (!res.containsKey('error')) {
items = res;
_localStorage.setItem(_collection, jsonEncode(items));
return true;
} else {
return false;
}
}
Future<bool> patch(String collection, Map<dynamic, dynamic> item) async {
if (!item.containsKey('id')) {
log('id needed', level: 3);
return false;
}
var itemId = item['id'];
item.remove('id');
var res = await _api.patch('/$collection/$itemId', item);
if (!res.containsKey('error')) {
int index = items.indexWhere((element) => element['id'] == item['id']);
items[index] = {...items[index], ...item};
return true;
} else {
return false;
}
}
// Future<bool> add(String collection, Map<dynamic, dynamic> item) async {}
// Future<bool> remove(String collection, {String id, int index}) async {}
}

+ 6
- 7
lib/store/user.dart View File

@ -90,7 +90,7 @@ class UserController extends GetxController {
void _deleteInCollection(String collection, String id,
[List<String> startPath]) {
var currentPath = startPath != null ? startPath : [];
var subSchema = schema;
var subSchema = userSchema;
currentPath.forEach((value) {
subSchema = subSchema[value];
@ -123,10 +123,9 @@ class UserController extends GetxController {
Future<bool> create(Map<dynamic, dynamic> item, String collection) async {
var res = await _api.post("/items/$collection", item);
if (!res.containsKey('error')) {
_createInCollection(collection, {
...item,
...{"id": res["data"]["id"]}
});
print(res);
_createInCollection(collection, res);
print(_user().value);
return true;
} else {
return false;
@ -136,7 +135,7 @@ class UserController extends GetxController {
void _createInCollection(String collection, Map<dynamic, dynamic> item,
[List<String> startPath]) {
var currentPath = startPath != null ? startPath : [];
var subSchema = schema;
var subSchema = userSchema;
currentPath.forEach((value) {
subSchema = subSchema[value];
@ -187,7 +186,7 @@ class UserController extends GetxController {
void _updateInCollection(String collection, Map<dynamic, dynamic> item,
[List<String> startPath]) {
var currentPath = startPath != null ? startPath : [];
var subSchema = schema;
var subSchema = userSchema;
currentPath.forEach((value) {
subSchema = subSchema[value];


+ 1
- 1
lib/views/account.dart View File

@ -9,7 +9,7 @@ class Account extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('my-acount'.tr),
title: Text('my-account'.tr),
),
body: Center(
child: Obx(


+ 17
- 5
lib/views/accountForm.dart View File

@ -39,11 +39,23 @@ class AccountFormState extends State<AccountForm> {
),
SizedBox(height: 16),
ElevatedButton(
onPressed: () => userController.patch(
{"id": 2, "title": "bbb"},
collection: "agency"),
// userController.patch({'first_name': firstName}),
child: Text('save'.tr))
onPressed: () => userController.patch(
{"id": 2, "title": "bbb"},
collection: "agency"),
// userController.patch({'first_name': firstName}),
child: Text('save'.tr),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: () => userController.create({
"picture": "acef13dc-5e11-48f8-9273-f0471a83a16d",
"step": "383dd1c2-3fd1-40d1-9b45-5f7639075c16",
"title": "test api create",
"client_thoughts": "client thoughts",
"provider_thoughts": "provider thoughts"
}, "repport"),
child: Text('test-create'.tr),
),
],
),
)),


+ 12
- 1
workspace.code-workspace View File

@ -4,5 +4,16 @@
"path": "."
}
],
"settings": {}
"settings": {},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Dart & Flutter",
"request": "launch",
"type": "dart",
"args": ["-d", "web-server","--web-port", "8000"]
}
]
}
}

Loading…
Cancel
Save