Skip to content

Commit

Permalink
Merge pull request #55 from eloiJhn/feature/dashboard
Browse files Browse the repository at this point in the history
Feature/dashboard
  • Loading branch information
PikPakPik authored Mar 19, 2024
2 parents c6dbcd1 + 998b38a commit 0b4f684
Show file tree
Hide file tree
Showing 12 changed files with 624 additions and 168 deletions.
10 changes: 9 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
"requiredField": "This field is required",
"organizationDescription": "Organization description",
"organizationWebsite": "Organization website",
"updateOrganization": "Update organization"
"updateOrganization": "Update organization",
"organizationCreated": "Create Organization",
"createOrganization": "Create",
"organizationCreationFailed": "Failed Organization",
"boardCreated": "Create board",
"boardCreationFailed": "Failed to create board",
"boardUpdated": "Board updated",
"boardName": "Board name",
"boardDescription": "Board description"
}
Empty file.
4 changes: 2 additions & 2 deletions lib/models/trello_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TrelloCard {
// final String coordinates;
// final String creationMethod;
// final DateTime dateLastActivity;
final String desc;
final String name;
// final Map<String, dynamic> descData;
final String? due;
// final String dueReminder;
Expand All @@ -23,7 +23,7 @@ class TrelloCard {
// final Map<String, dynamic> limits;
// final String locationName;
// final bool manualCoverAttachment;
final String name;
final String desc;
// final int pos;
// final String shortLink;
// final String shortUrl;
Expand Down
27 changes: 25 additions & 2 deletions lib/repositories/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import 'dart:convert';
import 'package:trelltech/models/board.dart';
import 'package:trelltech/models/trello_organization.dart';

import '../models/trello_card.dart';
import '../models/trello_list.dart';

/// Fetches the user's ID from Trello.
///
/// This function calls the Trello API to fetch the user's ID.
Expand Down Expand Up @@ -87,6 +90,16 @@ Future<List<Board>> getBoards(String apiKey, String token, String workspaceId) a
}
}

Future<void> updateBoard(String apiKey, String token, String boardId, Board board) async {
final response = await http.put(
Uri.parse('https://api.trello.com/1/boards/$boardId?key=$apiKey&token=$token&name=${board.name}'),
);

if (response.statusCode != 200) {
throw Exception('Failed to update board');
}
}

/// Fetches the user's workspaces from Trello.
///
/// This function calls the Trello API to fetch the user's workspaces.
Expand Down Expand Up @@ -122,6 +135,16 @@ Future<List<dynamic>> getLists(String apiKey, String token, String boardId) asyn
}
}

Future<void> updateList(String apiKey, String token, String listId, TrelloList list) async {
final response = await http.put(
Uri.parse('https://api.trello.com/1/lists/$listId?key=$apiKey&token=$token&name=${list.name}'),
);

if (response.statusCode != 200) {
throw Exception('Failed to update list');
}
}

/// Fetches the cards of a specific list from Trello.
///
/// This function calls the Trello API to fetch the cards of a specific list.
Expand Down Expand Up @@ -171,9 +194,9 @@ Future<void> deleteCard(String apiKey, String token, String cardId) async {
///
/// This function calls the Trello API to update the name of a specific card.
/// It requires the user's API key, token, the card's ID, and the new name of the card.
Future<void> updateCard(String apiKey, String token, String cardId, String desc) async {
Future<void> updateCard(String apiKey, String token, String cardId, TrelloCard card) async {
final response = await http.put(
Uri.parse('https://api.trello.com/1/cards/$cardId?key=$apiKey&token=$token&desc=$desc'),
Uri.parse('https://api.trello.com/1/cards/$cardId?key=$apiKey&token=$token&desc=${card.desc}&name=${card.name}'),
);

if (response.statusCode != 200) {
Expand Down
142 changes: 142 additions & 0 deletions lib/views/board/board_create_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:trelltech/models/board.dart';
import 'package:trelltech/models/trello_organization.dart';
import 'package:trelltech/repositories/api.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:trelltech/repositories/authentification.dart';

class CreateBoardScreen extends StatefulWidget {
const CreateBoardScreen({Key? key}) : super(key: key);

@override
_CreateBoardScreenState createState() => _CreateBoardScreenState();
}

class _CreateBoardScreenState extends State<CreateBoardScreen> {
final _formKey = GlobalKey<FormState>();
late TextEditingController _nameController;
late TextEditingController _descriptionController;
late bool _isLoading = false;

@override
void initState() {
super.initState();
_nameController = TextEditingController();
_descriptionController = TextEditingController();
}

void _submitForm() async {
if (_formKey.currentState!.validate()) {
setState(() {
_isLoading = true;
});

String? apiKey = dotenv.env['TRELLO_API_KEY'];
String? accessToken = await getAccessToken();

if (apiKey == null || accessToken == null) {
Fluttertoast.showToast(
msg: "API key or access token is null",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
setState(() {
_isLoading = false;
});
return;
}

try {
await createWorkspace(apiKey, accessToken, _nameController.text);

Fluttertoast.showToast(
msg: AppLocalizations.of(context)!.boardCreated,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0,
);
Navigator.pop(context, 'organizationCreated');
} catch (e) {
Fluttertoast.showToast(
msg: AppLocalizations.of(context)!.boardCreationFailed,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}

setState(() {
_isLoading = false;
});
}
}


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context)!.boardCreated),
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
TextFormField(
controller: _nameController,
decoration: InputDecoration(
labelText: AppLocalizations.of(context)!.boardName,
border: const OutlineInputBorder(),
),
validator: (value) {
if (value!.isEmpty) {
return AppLocalizations.of(context)!.requiredField;
}
return null;
},
),
const SizedBox(height: 16.0),
TextFormField(
controller: _descriptionController,
decoration: InputDecoration(
labelText: AppLocalizations.of(context)!.boardDescription,
border: const OutlineInputBorder(),
),
maxLines: 4,
),
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: _submitForm,
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, backgroundColor: Color(0xFF1C39A1),
),
child: Text(
AppLocalizations.of(context)!.boardCreated,
style: const TextStyle(fontSize: 16.0),
),
),
],
),
),
),
);
}
}

Loading

0 comments on commit 0b4f684

Please sign in to comment.