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: Add identity list #119

Merged
merged 5 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions ui/images/qingstor_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions ui/lib/common/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ 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);

Color regularLineColor = rgba(203, 213, 225, 1);
Color lightLineColor = rgba(226, 232, 240, 1);
99 changes: 99 additions & 0 deletions ui/lib/models/identity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'dart:convert';

class Credential {
String protocol;
List<String> args;

Credential({
required this.protocol,
required this.args,
});

factory Credential.fromMap(Map<String, dynamic> json) => Credential(
protocol: json["protocol"] ?? "",
args: List<String>.from(json["args"]),
);

Map<String, dynamic> toMap() => {
"protocol": protocol,
"args": args.toList(),
};
}

class Endpoint {
String protocol;
String host;
int port;

Endpoint({
required this.protocol,
required this.host,
required this.port,
});

factory Endpoint.fromMap(Map<String, dynamic> json) => Endpoint(
protocol: json["protocol"] ?? "",
host: json["host"] ?? "",
port: json["port"] ?? "",
);

Map<String, dynamic> toMap() => {
"protocol": protocol,
"host": host,
"port": port,
};
}

class Identity {
String name;
String type;
Credential credential;
Endpoint endpoint;

Identity({
required this.name,
required this.type,
required this.credential,
required this.endpoint,
});

factory Identity.fromMap(Map<String, dynamic> json) => Identity(
name: json["name"] ?? "",
type: json["type"] ?? "",
credential: Credential.fromMap(json["credential"] ?? ""),
endpoint: Endpoint.fromMap(json["endpoint"] ?? ""),
);

Map<String, dynamic> toMap() => {
"name": name,
"type": type,
"credential": credential.toMap(),
"endpoint": endpoint.toMap(),
};
}

class Identities {
List<Identity> identities;

Identities({
required this.identities,
});

factory Identities.fromList(List<Object> _identities) {
return Identities(
identities: List<Identity>.from(
_identities.map(
(identity) => Identity.fromMap(identity as Map<String, dynamic>),
),
),
);
}

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

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

int length() => identities.length;
}
1 change: 1 addition & 0 deletions ui/lib/modules/dashboard/create_task_dialog/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CreateTaskDialog extends StatelessWidget {
return Obx(
() => CommonDialog(
title: 'Create task'.tr,
width: 800,
content: Container(
width: 800,
height: 548,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,12 @@ class SourceLibrarySetting extends GetView<CreateTaskController> {
// ),
SizedBox(height: 24),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SelectableText(
'Bucket Name'.tr,
style: TextStyle(
color: regularFontColor,
fontSize: 12,
height: 1.67,
fontWeight: FontWeight.w500,
),
),
Expand Down Expand Up @@ -183,14 +181,12 @@ class SourceLibrarySetting extends GetView<CreateTaskController> {
children: [
SizedBox(height: 24),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SelectableText(
'Work Dir'.tr,
style: TextStyle(
color: regularFontColor,
fontSize: 12,
height: 1.67,
fontWeight: FontWeight.w500,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ class TargetLibrarySetting extends GetView<CreateTaskController> {
children: [
SizedBox(height: 24),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SelectableText(
'Bucket Name'.tr,
style: TextStyle(
color: regularFontColor,
fontSize: 12,
height: 1.67,
fontWeight: FontWeight.w500,
),
),
Expand Down Expand Up @@ -127,14 +125,12 @@ class TargetLibrarySetting extends GetView<CreateTaskController> {
children: [
SizedBox(height: 24),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SelectableText(
'Work Dir'.tr,
style: TextStyle(
color: regularFontColor,
fontSize: 12,
height: 1.67,
fontWeight: FontWeight.w500,
),
),
Expand Down
1 change: 1 addition & 0 deletions ui/lib/modules/dashboard/task_detail_dialog/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TaskDetailDialog extends GetView<DashboardController> {
Widget build(BuildContext context) {
return CommonDialog(
title: 'Task detail'.tr,
width: 600,
content: Container(
width: 600,
child: Padding(
Expand Down
56 changes: 56 additions & 0 deletions ui/lib/modules/identity/controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:get/get.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

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

class IdentityController extends GetxController {
RxBool loading = false.obs;
Rx<Identities> identities = Identities.fromList([]).obs;

final String query = '''
query {
identities(type: Qingstor) {
name
type
credential {
protocol
args
}
endpoint {
protocol
host
port
}
}
}
''';

void getIdentities() {
loading(true);

queryGraphQL(QueryOptions(document: gql(query))).then((result) {
loading(false);

if (result.data != null) {
identities(Identities.fromList(result.data["identities"] ?? []));
}
}).catchError((error) {
loading(false);
});
}

Future<QueryResult> deleteIdentity(Identity identity) {
String _query = '''
mutation {
deleteIdentity(input: { name: "${identity.name}", type: ${identity.type} }) { }
}
''';

return queryGraphQL(QueryOptions(document: gql(_query))).then((result) {
getIdentities();

return result;
});
}
}
70 changes: 70 additions & 0 deletions ui/lib/modules/identity/create_identity_dialog/controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import 'package:get/get.dart';
import 'package:flutter/widgets.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

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

class CreateIdentityController extends GetxController {
RxString type = 'Qingstor'.obs;
RxString name = ''.obs;
RxString credentialProtocol = 'hamc'.obs;
RxString credentialAccessKey = ''.obs;
RxString credentialSecretKey = ''.obs;
RxString endpointProtocol = ''.obs;
RxString endpointHost = ''.obs;
RxString endpointPort = ''.obs;

final autoValidateMode = AutovalidateMode.disabled.obs;

void closeDialog() {
Get.back();
Get.delete<CreateIdentityController>();
}

void onSubmit(getIdentities) {
createIdentity()
.then((value) => getIdentities())
.then((value) => closeDialog());
}

String get credential {
return '''
{
protocol: "hamc",
args: [
"$credentialAccessKey",
"$credentialSecretKey",
],
}
''';
}

String get endpoint {
return '''
{
protocol: "$endpointProtocol",
host: "$endpointHost",
port: $endpointPort,
}
''';
}

String get mutation {
return '''
mutation {
createIdentity(input: {
name: "$name",
type: $type,
credential: $credential,
endpoint: $endpoint,
}) { name }
}
''';
}

Future<QueryResult> createIdentity() {
return queryGraphQL(QueryOptions(document: gql(mutation))).then((result) {
return result;
});
}
}
Loading