1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 10:48:50 +01:00
git-touch-android-ios-app/lib/screens/organization.dart

184 lines
5.3 KiB
Dart
Raw Normal View History

2019-03-10 16:34:34 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/refresh_stateful.dart';
2019-09-23 12:28:33 +02:00
import 'package:git_touch/screens/repositories.dart';
2019-09-21 19:23:38 +02:00
import 'package:git_touch/screens/users.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-21 19:23:38 +02:00
import 'package:git_touch/widgets/entry_item.dart';
2019-09-23 12:28:33 +02:00
import 'package:git_touch/widgets/repository_item.dart';
2019-09-21 19:02:14 +02:00
import 'package:git_touch/widgets/table_view.dart';
import 'package:git_touch/widgets/user_item.dart';
2019-03-10 16:34:34 +01:00
import 'package:url_launcher/url_launcher.dart';
import 'package:share/share.dart';
2019-09-08 14:07:35 +02:00
import 'package:git_touch/models/settings.dart';
import 'package:provider/provider.dart';
2019-03-10 16:34:34 +01:00
import '../widgets/action.dart';
import '../utils/utils.dart';
2019-09-21 19:02:14 +02:00
class OrganizationScreen extends StatelessWidget {
2019-03-10 16:34:34 +01:00
final String login;
2019-09-21 19:02:14 +02:00
2019-03-10 16:34:34 +01:00
OrganizationScreen(this.login);
2019-09-21 19:02:14 +02:00
Iterable<Widget> _buildRepos(payload) {
String title;
2019-09-21 19:56:26 +02:00
List items = [];
2019-09-21 19:02:14 +02:00
2019-09-21 19:56:26 +02:00
var pinnedItems = payload['pinnedItems']['nodes'] as List;
var repositories = payload['pinnableItems']['nodes'] as List;
if (pinnedItems.isNotEmpty) {
2019-09-21 19:02:14 +02:00
title = 'pinned repositories';
2019-09-21 19:56:26 +02:00
items = pinnedItems;
} else if (repositories.isNotEmpty) {
title = 'popular repositories';
items = repositories;
2019-09-21 19:02:14 +02:00
}
items = items
.where((x) => x != null)
.toList(); // TODO: Pinned items may include somethings other than repo
if (items.isEmpty) return [];
return [
borderView1,
if (title != null) TableViewHeader(title),
...join(
borderView,
items.map((item) {
2019-09-23 12:28:33 +02:00
return RepositoryItem(item);
2019-09-21 19:02:14 +02:00
}).toList(),
)
];
}
@override
Widget build(BuildContext context) {
2019-09-25 11:06:36 +02:00
return RefreshStatefulScaffold(
2019-09-24 13:58:34 +02:00
onRefresh: () async {
2019-09-21 19:56:26 +02:00
// Use pinnableItems instead of organization here due to token permission
2019-09-21 19:02:14 +02:00
var data = await Provider.of<SettingsModel>(context).query('''
2019-03-10 16:34:34 +01:00
{
organization(login: "$login") {
name
avatarUrl
2019-09-21 19:02:14 +02:00
description
2019-03-10 16:34:34 +01:00
location
2019-09-21 19:02:14 +02:00
email
websiteUrl
2019-09-21 19:23:38 +02:00
url
2019-09-21 19:56:26 +02:00
pinnedItems(first: 6) {
2019-03-10 16:34:34 +01:00
nodes {
2019-09-03 10:35:13 +02:00
... on Repository {
$repoChunk
}
2019-03-10 16:34:34 +01:00
}
}
2019-09-21 19:56:26 +02:00
pinnableItems(first: 6, types: [REPOSITORY]) {
totalCount
nodes {
... on Repository {
$repoChunk
}
}
}
2019-09-21 19:23:38 +02:00
membersWithRole {
totalCount
}
2019-03-10 16:34:34 +01:00
}
}
''');
2019-09-21 19:02:14 +02:00
return data['organization'];
2019-03-10 16:34:34 +01:00
},
2019-09-21 19:02:14 +02:00
title: AppBarTitle('Organization'),
2019-03-10 16:34:34 +01:00
trailingBuilder: (payload) {
2019-09-25 15:41:44 +02:00
return ActionButton(
title: 'Organization Actions',
actions: [
MyAction(
text: 'Share',
onPress: () {
if (payload != null) {
Share.share(payload['url']);
}
},
),
MyAction(
text: 'Open in Browser',
onPress: () {
if (payload != null) {
launch(payload['url']);
}
},
),
],
);
2019-03-10 16:34:34 +01:00
},
bodyBuilder: (payload) {
return Column(
2019-09-21 19:02:14 +02:00
crossAxisAlignment: CrossAxisAlignment.stretch,
2019-03-10 16:34:34 +01:00
children: <Widget>[
2019-09-21 19:02:14 +02:00
UserItem(
login,
name: payload['name'],
avatarUrl: payload['avatarUrl'],
bio: payload['description'],
2019-03-10 16:34:34 +01:00
),
2019-09-21 19:23:38 +02:00
borderView,
Row(children: <Widget>[
2019-09-21 19:56:26 +02:00
EntryItem(
count: payload['pinnableItems']['totalCount'],
text: 'Repositories',
2019-09-23 12:28:33 +02:00
screenBuilder: (context) =>
RepositoriesScreen.ofOrganization(login),
2019-09-21 19:56:26 +02:00
),
2019-09-21 19:23:38 +02:00
EntryItem(
count: payload['membersWithRole']['totalCount'],
text: 'Members',
2019-09-23 15:25:18 +02:00
screenBuilder: (context) => UsersScreen.members(login),
2019-09-21 19:23:38 +02:00
),
]),
2019-09-21 19:02:14 +02:00
borderView1,
TableView(
hasIcon: true,
items: [
if (isNotNullOrEmpty(payload['location']))
TableViewItem(
leftIconData: Octicons.location,
text: Text(payload['location']),
onTap: () {
launch('https://www.google.com/maps/place/' +
(payload['location'] as String)
.replaceAll(RegExp(r'\s+'), ''));
},
),
if (isNotNullOrEmpty(payload['email']))
TableViewItem(
leftIconData: Octicons.mail,
text: Text(payload['email']),
onTap: () {
launch('mailto:' + payload['email']);
},
2019-03-10 16:34:34 +01:00
),
2019-09-21 19:02:14 +02:00
if (isNotNullOrEmpty(payload['websiteUrl']))
TableViewItem(
leftIconData: Octicons.link,
text: Text(payload['websiteUrl']),
onTap: () {
var url = payload['websiteUrl'] as String;
if (!url.startsWith('http')) {
url = 'http://$url';
}
launch(url);
},
2019-03-10 16:34:34 +01:00
),
2019-09-21 19:02:14 +02:00
],
2019-03-10 16:34:34 +01:00
),
2019-09-21 19:02:14 +02:00
..._buildRepos(payload),
2019-03-10 16:34:34 +01:00
],
);
},
);
}
}