Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Refactor create task dialog #117

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ui/lib/common/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ double opacity = 0.5;

Color rgba(int r, int g, int b, double a) => Color.fromRGBO(r, g, b, a);

Color headlineFontColor = rgba(100, 116, 139, 1);
Color headlineFontColor = rgba(51, 65, 85, 1);
Color regularFontColor = rgba(71, 85, 105, 1);
Color secondaryFontColor = rgba(100, 116, 139, 1);
Color disableFontColor = rgba(148, 163, 184, 1);

Color defaultColor = rgba(203, 213, 225, 1);
Color defaultDisabledColor = rgba(226, 232, 240, 1);

Color primaryColor = rgba(59, 130, 246, 1);
Color primaryHoveredColor = rgba(37, 99, 235, 1);
Color primaryPressedColor = rgba(29, 78, 216, 1);
Color primaryDisabledColor = rgba(59, 130, 246, opacity);
Color primaryColor = rgba(56, 86, 242, 1);
Color primaryHoveredColor = rgba(89, 126, 247, 1);
Color primaryPressedColor = rgba(29, 57, 196, 1);
Color primaryDisabledColor = rgba(111, 133, 245, opacity);
36 changes: 36 additions & 0 deletions ui/lib/models/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,39 @@ class TaskDetail {
.map((storage) => Storage.fromMap(storage))),
);
}

class Staff {
String id;

Staff({required this.id});

factory Staff.fromMap(Map<String, dynamic> json) => Staff(id: json["id"]);

Map<String, dynamic> toMap() => {
"id": id,
};

String toString() => json.encode(toMap());
}

class Staffs {
List<Staff> staffs;

Staffs({required this.staffs});

factory Staffs.fromList(List<Object> staffs) {
return Staffs(
staffs: List<Staff>.from(
staffs.map((x) => Staff.fromMap(x as Map<String, dynamic>)),
),
);
}

List<Map<String, dynamic>> toList() {
return staffs.map((staff) => staff.toMap()).toList();
}

String toString() => json.encode(toList());

int length() => staffs.length;
}
38 changes: 32 additions & 6 deletions ui/lib/modules/dashboard/create_task_dialog/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import 'package:flutter/widgets.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

import '../../../common/request.dart';
import '../../../models/task.dart';

class CreateTaskController extends GetxController {
RxInt step = 1.obs;
RxBool isEditingName = false.obs;
RxBool isCreatingIdentity = false.obs;

RxString name = ''.obs;
RxString srcType = ''.obs;
RxString srcPath = '/'.obs;
Expand Down Expand Up @@ -105,8 +110,27 @@ class CreateTaskController extends GetxController {
''';
}

final String staffQuery = '''
query {
staffs {
id
}
}
''';

Future<Staffs> getStaffs() {
return queryGraphQL(QueryOptions(document: gql(staffQuery))).then((result) {
if (result.data != null) {
return Staffs.fromList(result.data["staffs"] ?? []);
} else {
return Staffs.fromList([]);
}
});
}

Future<QueryResult> createTask() {
String _query = '''
return getStaffs().then((staffs) {
String _query = '''
mutation {
createTask(input: {
name: "$name",
Expand All @@ -116,15 +140,17 @@ class CreateTaskController extends GetxController {
key: "recursive",
value: "true",
},
staffs: {
id: "",
},
staffs: ${staffs.toList()},
}) { id }
}
''';

return queryGraphQL(QueryOptions(document: gql(_query))).then((result) {
return result;
return queryGraphQL(QueryOptions(document: gql(staffQuery)))
.then((result) {
return queryGraphQL(QueryOptions(document: gql(_query))).then((result) {
return result;
});
});
});
}
}
Loading