Skip to content

Commit

Permalink
Merge pull request #67 from eloiJhn/feature/boards
Browse files Browse the repository at this point in the history
Feature/boards
  • Loading branch information
PikPakPik authored Mar 21, 2024
2 parents 9094981 + 966062d commit 00f0204
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 90 deletions.
3 changes: 3 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
"organizationDescription": "Organization description",
"organizationWebsite": "Organization website",
"updateOrganization": "Update organization",
"updateBoard": "Update board",
"organizationCreated": "Create Organization",
"createOrganization": "Create",
"organizationCreationFailed": "Failed Organization",
"boardCreated": "Create board",
"editBoard": "Edit board",
"boardCreationFailed": "Failed to create board",
"boardUpdateFailed": "Board update failed",
"boardUpdated": "Board updated",
"boardName": "Board name",
"boardDescription": "Board description"
Expand Down
23 changes: 21 additions & 2 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,24 @@
"dashboard": "Tableau de bord",
"logout": "Déconnexion",
"openBoard": "Ouvrir",
"addCard": "Ajouter une carte"
}
"addCard": "Ajouter une carte",
"organizationUpdated": "Organisation mise à jour",
"organizationUpdateFailed": "Échec de la mise à jour de l'organisation",
"editOrganization": "Modifier l'organisation",
"organizationName": "Nom de l'organisation",
"requiredField": "Ce champ est requis",
"organizationDescription": "Description de l'organisation",
"organizationWebsite": "Site Web de l'organisation",
"updateOrganization": "Mettre à jour l'organisation",
"updateBoard": "Mettre à jour le tableau",
"organizationCreated": "Créer une organisation",
"createOrganization": "Créer",
"organizationCreationFailed": "Échec de la création de l'organisation",
"boardCreated": "Créer un tableau",
"editBoard": "Modifier le tableau",
"boardCreationFailed": "Échec de la création du tableau",
"boardUpdateFailed": "Échec de la mise à jour du tableau",
"boardUpdated": "Tableau mis à jour",
"boardName": "Nom du tableau",
"boardDescription": "Description du tableau"
}
95 changes: 36 additions & 59 deletions lib/models/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,25 @@ class Board {
String? desc;
bool closed;
String? idMemberCreator;
String idOrganization;
bool pinned;
String url;
String shortUrl;
String? idOrganization;
bool? pinned;
String? url;
String? shortUrl;
String? bgImage;
String? bgColor;
/*
Map<String, String> labelNames;
Map<String, dynamic> limits;
bool starred;
String memberships;
String shortLink;
bool subscribed;
String powerUps;
String dateLastActivity;
String dateLastView;
String idTags;
String datePluginDisable;
String creationMethod;
int ixUpdate;
String templateGallery;
bool enterpriseOwned;
*/

Board({
required this.id,
required this.name,
this.desc,
required this.closed,
this.idMemberCreator,
required this.idOrganization,
required this.pinned,
required this.url,
required this.shortUrl,
this.idOrganization,
this.pinned,
this.url,
this.shortUrl,
this.bgImage,
this.bgColor,
/*
required this.labelNames,
required this.limits,
required this.starred,
required this.memberships,
required this.shortLink,
required this.subscribed,
required this.powerUps,
required this.dateLastActivity,
required this.dateLastView,
required this.idTags,
required this.datePluginDisable,
required this.creationMethod,
required this.ixUpdate,
required this.templateGallery,
required this.enterpriseOwned,
*/
});

factory Board.fromJson(Map<String, dynamic> json) {
Expand All @@ -72,23 +38,34 @@ class Board {
shortUrl: json['shortUrl'],
bgImage: json['prefs']['backgroundImage'],
bgColor: json['prefs']['backgroundColor'],
/*
labelNames: Map<String, String>.from(json['labelNames']),
limits: Map<String, dynamic>.from(json['limits']),
starred: json['starred'],
memberships: json['memberships'],
shortLink: json['shortLink'],
subscribed: json['subscribed'],
powerUps: json['powerUps'],
dateLastActivity: json['dateLastActivity'],
dateLastView: json['dateLastView'],
idTags: json['idTags'],
datePluginDisable: json['datePluginDisable'],
creationMethod: json['creationMethod'],
ixUpdate: json['ixUpdate'],
templateGallery: json['templateGallery'],
enterpriseOwned: json['enterpriseOwned'],
*/
);
}

Board copyWith({
String? id,
String? name,
String? desc,
bool? closed,
String? idMemberCreator,
String? idOrganization,
bool? pinned,
String? url,
String? shortUrl,
String? bgImage,
String? bgColor,
}) {
return Board(
id: id ?? this.id,
name: name ?? this.name,
desc: desc ?? this.desc,
closed: closed ?? this.closed,
idMemberCreator: idMemberCreator ?? this.idMemberCreator,
idOrganization: idOrganization ?? this.idOrganization,
pinned: pinned ?? this.pinned,
url: url ?? this.url,
shortUrl: shortUrl ?? this.shortUrl,
bgImage: bgImage ?? this.bgImage,
bgColor: bgColor ?? this.bgColor,
);
}
}
47 changes: 41 additions & 6 deletions lib/repositories/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,15 @@ Future<List<Board>> getBoards(
}
}

Future<void> updateBoard(
String apiKey, String? token, String boardId, Board board) async {
Future<bool> 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}'),
Uri.parse('https://api.trello.com/1/boards/$boardId?key=$apiKey&token=$token&name=${board.name}&desc=${board.desc}'),
);

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

/// Fetches the user's workspaces from Trello.
Expand Down Expand Up @@ -229,8 +228,16 @@ Future<void> createCard(
'https://api.trello.com/1/cards?key=$apiKey&token=$token&idList=$listId&name=$name'),
);

if (response.statusCode != 200) {
throw Exception('Failed to create card');
if (response.statusCode == 200) {
Fluttertoast.showToast(
msg: "Ajout effectué",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
} else {
throw Exception('Failed to create a card');
}
}

Expand Down Expand Up @@ -353,6 +360,34 @@ Future<TrelloOrganization> getWorkspace(
}
}

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

if (response.statusCode == 200) {
var data = jsonDecode(response.body);
return Board.fromJson(data);
} else {
throw Exception('Failed to load workspace');
}
}


/// Deletes a specific board from Trello.
///
/// This function calls the Trello API to delete a specific board.
/// It requires the user's API key, token, and the board's ID.
Future<void> deleteBoard(String apiKey, String token, String boardId) async {
final response = await http.delete(
Uri.parse('https://api.trello.com/1/boards/$boardId?key=$apiKey&token=$token'),
);

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

/// Fetches the templates of boards in the gallery from Trello.
///
/// This function calls the Trello API to fetch the templates of boards in the gallery.
Expand Down
157 changes: 157 additions & 0 deletions lib/views/board/board_edit_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
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';
import 'package:trelltech/views/board/workspace_view.dart';

class EditBoardScreen extends StatefulWidget {
final String boardId;

const EditBoardScreen({super.key, required this.boardId});

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

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

@override
void initState() {
super.initState();
_initControllers();
_fetchBoardDetails();
}

void _initControllers() {
_nameController = TextEditingController();
_descriptionController = TextEditingController();
}

Future<void> _fetchBoardDetails() async {
setState(() {
_isLoading = true;
});

final board = await getBoard(dotenv.env['TRELLO_API_KEY']!,
await getAccessToken(), widget.boardId);

_nameController.text = board.name;
_descriptionController.text = board.desc!;

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

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

final board = Board(
id: widget.boardId,
name: _nameController.text,
desc: _descriptionController.text,
closed: false,
);

final success = await updateBoard(dotenv.env['TRELLO_API_KEY']!,
await getAccessToken(), widget.boardId, board);

if (success) {
Navigator.pop(context, board);
Fluttertoast.showToast(
msg: AppLocalizations.of(context)!.boardUpdated,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0,
);


} else {
Fluttertoast.showToast(
msg: AppLocalizations.of(context)!.boardUpdateFailed,
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)!.editBoard),
),
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)!
.organizationDescription,
border: const OutlineInputBorder(),
),
maxLines: 4,
),
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: _submitForm,
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, backgroundColor: const Color(0xFF1C39A1), // text color
),
child: Text(
AppLocalizations.of(context)!.updateBoard,
style: const TextStyle(fontSize: 16.0),
),
),
],
),
),
),
);
}
}
Loading

0 comments on commit 00f0204

Please sign in to comment.