git-touch-android-ios-app/lib/router.dart

303 lines
11 KiB
Dart
Raw Normal View History

2020-02-01 06:26:14 +01:00
import 'package:fluro/fluro.dart';
2020-02-03 07:40:56 +01:00
import 'package:git_touch/screens/bb_commits.dart';
2020-02-02 12:50:00 +01:00
import 'package:git_touch/screens/bb_object.dart';
2020-02-02 11:58:05 +01:00
import 'package:git_touch/screens/bb_repo.dart';
import 'package:git_touch/screens/bb_user.dart';
2020-02-01 06:26:14 +01:00
import 'package:git_touch/screens/code_theme.dart';
2020-02-07 07:17:05 +01:00
import 'package:git_touch/screens/gh_commits.dart';
import 'package:git_touch/screens/gh_contributors.dart';
2020-04-30 18:04:24 +02:00
import 'package:git_touch/screens/gh_files.dart';
import 'package:git_touch/screens/gh_org_repos.dart';
2020-02-29 10:06:47 +01:00
import 'package:git_touch/screens/gl_commit.dart';
import 'package:git_touch/screens/gl_starrers.dart';
2020-02-07 15:20:06 +01:00
import 'package:git_touch/screens/gt_commits.dart';
import 'package:git_touch/screens/gt_issues.dart';
import 'package:git_touch/screens/gt_object.dart';
import 'package:git_touch/screens/gt_org.dart';
import 'package:git_touch/screens/gt_repo.dart';
import 'package:git_touch/screens/gt_user.dart';
2020-02-07 15:26:37 +01:00
import 'package:git_touch/screens/gl_blob.dart';
import 'package:git_touch/screens/gl_commits.dart';
import 'package:git_touch/screens/gl_group.dart';
import 'package:git_touch/screens/gl_issue.dart';
import 'package:git_touch/screens/gl_issues.dart';
import 'package:git_touch/screens/gl_members.dart';
import 'package:git_touch/screens/gl_merge_requests.dart';
import 'package:git_touch/screens/gl_project.dart';
import 'package:git_touch/screens/gl_tree.dart';
import 'package:git_touch/screens/gl_user.dart';
2020-02-07 07:17:05 +01:00
import 'package:git_touch/screens/gh_issue.dart';
import 'package:git_touch/screens/gh_issue_form.dart';
import 'package:git_touch/screens/gh_issues.dart';
2020-02-01 06:26:14 +01:00
import 'package:git_touch/screens/login.dart';
2020-02-07 07:17:05 +01:00
import 'package:git_touch/screens/gh_object.dart';
import 'package:git_touch/screens/gh_pulls.dart';
import 'package:git_touch/screens/gh_repos.dart';
import 'package:git_touch/screens/gh_repo.dart';
2020-02-01 06:26:14 +01:00
import 'package:git_touch/screens/settings.dart';
2020-02-07 07:17:05 +01:00
import 'package:git_touch/screens/gh_user.dart';
import 'package:git_touch/screens/gh_users.dart';
import 'package:git_touch/screens/gh_user_organization.dart';
2020-04-30 18:04:24 +02:00
import 'package:git_touch/screens/gh_gists.dart';
2020-02-01 06:26:14 +01:00
class RouterScreen {
String path;
HandlerFunc handler;
RouterScreen(this.path, this.handler);
}
class CommonRouter {
static const prefix = '';
static final routes = [
CommonRouter.codeTheme,
CommonRouter.login,
CommonRouter.settings
];
static final codeTheme = RouterScreen('/choose-code-theme', (context, p) {
return CodeThemeScreen();
});
static final login = RouterScreen('/login', (context, p) => LoginScreen());
static final settings =
RouterScreen('/settings', (context, parameters) => SettingsScreen());
}
class GithubRouter {
static const prefix = ''; // TODO: '/github';
static final routes = [
GithubRouter.user,
GithubRouter.repo,
GithubRouter.issueAdd,
GithubRouter.issues,
GithubRouter.pulls,
GithubRouter.issue,
GithubRouter.pull,
GithubRouter.commits,
GithubRouter.object,
GithubRouter.stargazers,
GithubRouter.watchers,
GithubRouter.contributors,
2020-04-30 18:04:24 +02:00
GithubRouter.files,
2020-02-01 06:26:14 +01:00
];
static final user = RouterScreen('/:login', (_, p) {
final login = p['login'].first;
final tab = p['tab']?.first;
switch (tab) {
case 'followers':
2020-02-07 07:17:05 +01:00
return GhUsersScreen(login, UsersScreenType.follower);
2020-02-01 06:26:14 +01:00
case 'following':
2020-02-07 07:17:05 +01:00
return GhUsersScreen(login, UsersScreenType.following);
2020-02-01 06:26:14 +01:00
case 'people':
2020-02-07 07:17:05 +01:00
return GhUsersScreen(login, UsersScreenType.member);
2020-02-01 06:26:14 +01:00
case 'stars':
2020-02-07 07:17:05 +01:00
return GhReposScreen.stars(login);
2020-02-01 06:26:14 +01:00
case 'repositories':
2020-02-07 07:17:05 +01:00
return GhReposScreen(login);
case 'orgrepo':
return GhOrgReposScreen(login);
case 'organizations':
return GhUserOrganizationScreen(login);
2020-04-30 18:04:24 +02:00
case 'gists':
return GhGistsScreen(login);
2020-02-01 06:26:14 +01:00
default:
2020-02-07 07:17:05 +01:00
return GhUserScreen(login);
2020-02-01 06:26:14 +01:00
}
});
static final repo = RouterScreen('/:owner/:name', (_, p) {
if (p['ref'] == null) {
2020-02-07 07:17:05 +01:00
return GhRepoScreen(p['owner'].first, p['name'].first);
2020-02-01 06:26:14 +01:00
} else {
2020-02-07 07:17:05 +01:00
return GhRepoScreen(p['owner'].first, p['name'].first,
2020-02-01 06:26:14 +01:00
branch: p['ref'].first);
}
});
static final issueAdd = RouterScreen('/:owner/:name/issues/new', (_, p) {
2020-02-07 07:17:05 +01:00
return GhIssueFormScreen(p['owner'].first, p['name'].first);
2020-02-01 06:26:14 +01:00
});
static final issues = RouterScreen('/:owner/:name/issues',
2020-02-07 07:17:05 +01:00
(context, p) => GhIssuesScreen(p['owner'].first, p['name'].first));
2020-02-01 06:26:14 +01:00
static final pulls = RouterScreen('/:owner/:name/pulls',
2020-02-07 07:17:05 +01:00
(context, p) => GhPullsScreen(p['owner'].first, p['name'].first));
2020-02-01 06:26:14 +01:00
static final issue = RouterScreen(
'/:owner/:name/issues/:number',
2020-02-07 07:17:05 +01:00
(context, p) => GhIssueScreen(
2020-02-01 06:26:14 +01:00
p['owner'].first, p['name'].first, int.parse(p['number'].first)));
static final pull = RouterScreen(
'/:owner/:name/pull/:number',
2020-02-07 07:17:05 +01:00
(context, p) => GhIssueScreen(
2020-02-01 06:26:14 +01:00
p['owner'].first, p['name'].first, int.parse(p['number'].first),
isPullRequest: true));
2020-04-30 18:04:24 +02:00
static final files = RouterScreen(
'/:owner/:name/pull/:number/files',
(context, p) => GhFilesScreen(
p['owner'].first,
p['name'].first,
int.parse(p['number'].first),
));
2020-02-01 06:26:14 +01:00
static final commits = RouterScreen('/:owner/:name/commits',
2020-02-07 07:17:05 +01:00
(context, p) => GhCommitsScreen(p['owner'].first, p['name'].first));
2020-02-01 06:26:14 +01:00
static final object = RouterScreen('/:owner/:name/blob/:ref', (_, p) {
2020-02-07 07:17:05 +01:00
return GhObjectScreen(
2020-02-01 06:26:14 +01:00
p['owner'].first,
p['name'].first,
p['ref'].first,
path: p['path']?.first,
raw: p['raw']?.first,
);
});
static final stargazers = RouterScreen('/:owner/:name/stargazers', (_, p) {
2020-02-07 07:17:05 +01:00
return GhUsersScreen(p['owner'].first, UsersScreenType.star,
2020-02-01 06:26:14 +01:00
repoName: p['name'].first);
});
static final watchers = RouterScreen('/:owner/:name/watchers', (_, p) {
2020-02-07 07:17:05 +01:00
return GhUsersScreen(p['owner'].first, UsersScreenType.watch,
2020-02-01 06:26:14 +01:00
repoName: p['name'].first);
});
static final contributors =
RouterScreen('/:owner/:name/contributors', (_, p) {
return GhContributorsScreen(p['owner'].first, p['name'].first);
});
2020-02-01 06:26:14 +01:00
}
class GitlabRouter {
static const prefix = '/gitlab';
static final routes = [
GitlabRouter.user,
GitlabRouter.group,
GitlabRouter.blob,
GitlabRouter.tree,
GitlabRouter.project,
GitlabRouter.starrers,
2020-02-01 06:26:14 +01:00
GitlabRouter.issues,
GitlabRouter.mergeRequests,
GitlabRouter.commits,
2020-02-29 10:06:47 +01:00
GitlabRouter.commit,
2020-02-01 06:26:14 +01:00
GitlabRouter.projectMembers,
GitlabRouter.groupMembers,
GitlabRouter.issue,
];
static final user = RouterScreen(
2020-02-07 15:26:37 +01:00
'/user/:id', (context, p) => GlUserScreen(int.parse(p['id'].first)));
static final group = RouterScreen(
'/group/:id', (context, p) => GlGroupScreen(int.parse(p['id'].first)));
2020-02-01 06:26:14 +01:00
static final blob = RouterScreen(
'/projects/:id/blob/:ref',
2020-02-07 15:26:37 +01:00
(context, params) => GlBlobScreen(
int.parse(params['id'].first), params['ref'].first,
2020-02-01 06:26:14 +01:00
path: params['path']?.first));
static final tree = RouterScreen(
'/projects/:id/tree/:ref',
2020-02-07 15:26:37 +01:00
(context, params) => GlTreeScreen(
int.parse(params['id'].first), params['ref'].first,
2020-02-01 06:26:14 +01:00
path: params['path']?.first));
static final project = RouterScreen('/projects/:id',
2020-02-07 15:26:37 +01:00
(context, params) => GlProjectScreen(int.parse(params['id'].first)));
static final starrers = RouterScreen('/projects/:id/starrers',
(context, params) => GlStarrersScreen(int.parse(params['id'].first)));
2020-02-01 06:26:14 +01:00
static final issues = RouterScreen(
'/projects/:id/issues',
2020-02-07 15:26:37 +01:00
(context, params) => GlIssuesScreen(
2020-02-01 06:26:14 +01:00
params['id'].first,
prefix: params['prefix'].first,
));
static final mergeRequests = RouterScreen(
'/projects/:id/merge_requests',
2020-02-07 15:26:37 +01:00
(context, params) => GlMergeRequestsScreen(
2020-02-01 06:26:14 +01:00
params['id'].first,
prefix: params['prefix'].first,
));
2020-02-01 06:37:44 +01:00
static final commits = RouterScreen(
'/projects/:id/commits',
2020-02-07 15:26:37 +01:00
(context, params) =>
GlCommitsScreen(params['id'].first, prefix: params['prefix'].first));
2020-02-29 10:06:47 +01:00
static final commit = RouterScreen(
'/projects/:id/commit/:sha',
(context, params) =>
GlCommitScreen(params['id'].first, sha: params['sha'].first));
2020-02-01 06:26:14 +01:00
static final projectMembers = RouterScreen(
'/projects/:id/members',
(context, parameters) =>
2020-02-07 15:26:37 +01:00
GlMembersScreen(int.parse(parameters['id'].first), 'projects'));
2020-02-01 06:26:14 +01:00
static final groupMembers = RouterScreen(
'/groups/:id/members',
(context, parameters) =>
2020-02-07 15:26:37 +01:00
GlMembersScreen(int.parse(parameters['id'].first), 'groups'));
2020-02-01 06:26:14 +01:00
static final issue = RouterScreen(
'/gitlab/projects/:id/issues/:iid',
(context, params) {
2020-02-07 15:26:37 +01:00
return GlIssueScreen(
2020-02-01 06:26:14 +01:00
int.parse(params['id'].first),
int.parse(params['iid'].first),
);
},
);
}
class GiteaRouter {
static const prefix = '/gitea';
static final routes = [
GiteaRouter.user,
GiteaRouter.repo,
2020-02-01 08:21:42 +01:00
GiteaRouter.object,
GiteaRouter.commits,
2020-02-01 08:42:10 +01:00
GiteaRouter.issues,
GiteaRouter.pulls,
2020-02-01 06:26:14 +01:00
];
static final user = RouterScreen(
'/:login',
2020-02-01 12:07:51 +01:00
(context, params) => params['org'].first == '1'
2020-02-07 15:20:06 +01:00
? GtOrgScreen(params['login'].first)
: GtUserScreen(params['login'].first),
2020-02-01 06:26:14 +01:00
);
static final repo = RouterScreen(
'/:owner/:name',
(context, params) =>
2020-02-07 15:20:06 +01:00
GtRepoScreen(params['owner'].first, params['name'].first),
2020-02-01 06:26:14 +01:00
);
static final object = RouterScreen(
2020-02-01 08:21:42 +01:00
'/:owner/:name/blob',
2020-02-07 15:20:06 +01:00
(context, params) => GtObjectScreen(
2020-02-01 06:26:14 +01:00
params['owner'].first,
params['name'].first,
path: params['path']?.first,
),
);
2020-02-01 08:21:42 +01:00
static final commits = RouterScreen('/:owner/:name/commits',
2020-02-07 15:20:06 +01:00
(_, p) => GtCommitsScreen(p['owner'].first, p['name'].first));
2020-02-01 08:42:10 +01:00
static final issues = RouterScreen('/:owner/:name/issues',
2020-02-07 15:20:06 +01:00
(_, p) => GtIssuesScreen(p['owner'].first, p['name'].first));
static final pulls = RouterScreen('/:owner/:name/pulls',
(_, p) => GtIssuesScreen(p['owner'].first, p['name'].first, isPr: true));
2020-02-01 06:26:14 +01:00
}
2020-02-02 11:58:05 +01:00
class BitbucketRouter {
static const prefix = '/bitbucket';
static final routes = [
BitbucketRouter.user,
BitbucketRouter.repo,
2020-02-02 12:50:00 +01:00
BitbucketRouter.object,
2020-02-03 07:40:56 +01:00
BitbucketRouter.commits,
2020-02-02 11:58:05 +01:00
];
static final user = RouterScreen(
2020-02-02 15:43:01 +01:00
'/:login',
(context, params) => BbUserScreen(params['login'].first,
isTeam: params['team'].first == '1'));
2020-02-02 11:58:05 +01:00
static final repo = RouterScreen(
'/:owner/:name',
(context, params) =>
BbRepoScreen(params['owner'].first, params['name'].first),
);
2020-02-02 12:50:00 +01:00
static final object = RouterScreen(
'/:owner/:name/src/:ref',
(context, params) => BbObjectScreen(
params['owner'].first,
params['name'].first,
params['ref'].first,
path: params['path']?.first,
),
);
2020-02-03 07:40:56 +01:00
static final commits = RouterScreen(
'/:owner/:name/commits/:ref',
(_, p) =>
BbCommitsScreen(p['owner'].first, p['name'].first, p['ref'].first));
2020-02-02 11:58:05 +01:00
}