-
Notifications
You must be signed in to change notification settings - Fork 2
Added tests and functionality #101
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
Open
herrone
wants to merge
7
commits into
develop
Choose a base branch
from
feature/teamMemberManage
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a23c259
push
stefan4h 42ef38c
yes
stefan4h f9c814f
push
stefan4h 5785040
Added xaml for TeamMembers
herrone 59a3f5a
Merge branch 'feature/MAUI-APP#71' into feature/teamMemberManage
herrone 57c7c8f
Added in functionality for team member
herrone 3aef98f
Added in tests and functionality for filtering
herrone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using SQLite; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.Linq; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MauiApp1.Models | ||
| { | ||
| internal class Team : INotifyPropertyChanged | ||
| { | ||
| [PrimaryKey, AutoIncrement] | ||
| public int id { get; set; } | ||
| private int maxSize; | ||
| public int MaxSize | ||
| { | ||
| get => maxSize; | ||
| set => SetField(ref maxSize, value); | ||
| } | ||
|
|
||
| private string skillsRequired; | ||
| public string SkillsRequired | ||
| { | ||
| get => skillsRequired; | ||
| set => SetField(ref skillsRequired, value); | ||
| } | ||
|
|
||
| private DateTime startDate; | ||
| public DateTime StartDate | ||
| { | ||
| get => startDate; | ||
| set => SetField(ref startDate, value); | ||
| } | ||
|
|
||
| private DateTime endDate; | ||
| public DateTime EndDate | ||
| { | ||
| get => endDate; | ||
| set => SetField(ref endDate, value); | ||
| } | ||
|
|
||
| public event PropertyChangedEventHandler PropertyChanged; | ||
| protected void OnPropertyChanged(string propertyName) => | ||
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
|
|
||
| protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = "") | ||
| { | ||
| if (EqualityComparer<T>.Default.Equals(field, value)) return false; | ||
| field = value; | ||
| OnPropertyChanged(propertyName); | ||
| return true; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using SQLite; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.Linq; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MauiApp1.Models | ||
| { | ||
| public class TeamMember : INotifyPropertyChanged | ||
| { | ||
| [PrimaryKey, AutoIncrement] | ||
| public int id { get; set; } | ||
| private string firstname; | ||
| public string Firstname | ||
| { | ||
| get => firstname; | ||
| set => SetField(ref firstname, value); | ||
| } | ||
|
|
||
| private string lastname; | ||
| public string Lastname | ||
| { | ||
| get => lastname; | ||
| set => SetField(ref lastname, value); | ||
| } | ||
|
|
||
| private string email; | ||
| public string Email | ||
| { | ||
| get => email; | ||
| set => SetField(ref email, value); | ||
| } | ||
|
|
||
| public event PropertyChangedEventHandler PropertyChanged; | ||
| protected void OnPropertyChanged(string propertyName) => | ||
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
|
|
||
| protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = "") | ||
| { | ||
| if (EqualityComparer<T>.Default.Equals(field, value)) return false; | ||
| field = value; | ||
| OnPropertyChanged(propertyName); | ||
| return true; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using MauiApp1.Models; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MauiApp1.Services | ||
| { | ||
| public interface ITeamMemberService | ||
| { | ||
| Task<List<TeamMember>> GetTeamMemberList(); | ||
| Task<int> AddTeamMember(TeamMember teamMember); | ||
| Task<int> DeleteTeamMember(TeamMember teamMember); | ||
| Task<int> UpdateTeamMember(TeamMember teamMember); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using MauiApp1.Data; | ||
| using MauiApp1.Models; | ||
| using SQLite; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MauiApp1.Services | ||
| { | ||
| public class TeamMemberService : ITeamMemberService | ||
| { | ||
| private SQLiteAsyncConnection _dbConn; | ||
| /*! <summary> | ||
| Method that initiates connection to database. Will create the OrderStatus table if connected. | ||
| </summary> */ | ||
| private async Task SetUpDb() | ||
| { | ||
| if (_dbConn != null) | ||
| return; | ||
|
|
||
|
|
||
| _dbConn = new SQLiteAsyncConnection(DatabaseSettings.DBPath, DatabaseSettings.Flags); | ||
| await _dbConn.CreateTableAsync<OrderStatus>(); | ||
| } | ||
|
|
||
| public async Task<int> AddTeamMember(TeamMember teamMember) | ||
| { | ||
| await SetUpDb(); | ||
| return await _dbConn.InsertAsync(teamMember); | ||
| } | ||
|
|
||
| public async Task<int> DeleteTeamMember(TeamMember teamMember) | ||
| { | ||
| await SetUpDb(); | ||
| return await _dbConn.DeleteAsync(teamMember); | ||
| } | ||
|
|
||
| public async Task<List<TeamMember>> GetTeamMemberList() | ||
| { | ||
| await SetUpDb(); | ||
| return await _dbConn.Table<TeamMember>().ToListAsync(); | ||
| } | ||
|
|
||
| public async Task<int> UpdateTeamMember(TeamMember teamMember) | ||
| { | ||
| await SetUpDb(); | ||
| return await _dbConn.UpdateAsync(teamMember); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MauiApp1.Tests | ||
| { | ||
| internal class TeamMembersPageTests | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="MauiApp1.Views.TeamMembersPage" | ||
| Title="TeamMember Page"> | ||
| <VerticalStackLayout Spacing="10" Margin="5"> | ||
| <Editor x:Name="txe_teamMemberFirstName" Placeholder="First Name" /> | ||
| <Editor x:Name="txe_teamMemberLastName" Placeholder="Last Name" /> | ||
| <Editor x:Name="txe_teamMemberEmail" Placeholder="Email" /> | ||
|
|
||
|
|
||
| <Grid ColumnDefinitions="*,*" ColumnSpacing="4"> | ||
| <Button Text="Save" | ||
| Clicked="SaveButton_Clicked" /> | ||
|
|
||
| <Button Grid.Column="1" | ||
| Text="Delete" | ||
| Clicked="DeleteButton_Clicked" /> | ||
| </Grid> | ||
|
|
||
| <ListView x:Name="ltv_teamMembers" Background="white" ItemSelected="ltv_teamMembers_ItemSelected"> | ||
| <ListView.ItemTemplate> | ||
| <DataTemplate> | ||
| <Label Text="{Binding FirstName}" TextColor="Black" FontAttributes="Bold" /> | ||
| <Label Text="{Binding LastName + ' - ' + Email}" TextColor="Gray" /> | ||
| </DataTemplate> | ||
| </ListView.ItemTemplate> | ||
| </ListView> | ||
| </VerticalStackLayout> | ||
| </ContentPage> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| using MauiApp1.Models; | ||
| using MauiApp1.Services; | ||
| using System; | ||
| using System.Collections.ObjectModel; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
||
| /*! The TeamMembersPage class allows for the basic functions | ||
| * implemented in the TeamMemberService class to be used within | ||
| * the UI | ||
| */ | ||
|
|
||
| namespace MauiApp1.Views; | ||
|
|
||
| public partial class TeamMembersPage : ContentPage | ||
| { | ||
| TeamMember selectedTeamMember = null; | ||
| ITeamMemberService teamMemberService; | ||
| ObservableCollection<TeamMember> teamMembers = new ObservableCollection<TeamMember>(); | ||
|
|
||
| //! public initialisation of components | ||
| public TeamMembersPage() | ||
| { | ||
| InitializeComponent(); | ||
| this.BindingContext = this; | ||
| this.teamMemberService = new TeamMemberService(); | ||
|
|
||
| Task.Run(async () => await LoadTeamMembers()); | ||
| } | ||
|
|
||
|
|
||
| //! Task to load teamMembers into a variable | ||
| private async Task LoadTeamMembers() | ||
| { | ||
| teamMembers = new ObservableCollection<TeamMember>(await teamMemberService.GetTeamMemberList()); | ||
| ltv_teamMembers.ItemsSource = teamMembers; | ||
| } | ||
|
|
||
| /*! | ||
| * Detect save button being clicked | ||
| * @param sender (Object) the sender object created by the event | ||
| * @param e (EventArgs) the arguments passed into the event | ||
| */ | ||
| private void SaveButton_Clicked(object sender, EventArgs e) | ||
| { | ||
| string firstName = txe_teamMemberFirstName.Text; | ||
| string lastName = txe_teamMemberLastName.Text; | ||
| string email = txe_teamMemberEmail.Text; | ||
|
|
||
| if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(email)) return; | ||
|
|
||
| var teamMember = new TeamMember() | ||
| { | ||
| Firstname = firstName, | ||
| Lastname = lastName, | ||
| Email = email | ||
| }; | ||
|
|
||
| teamMemberService.AddTeamMember(teamMember); | ||
| teamMembers.Add(teamMember); | ||
|
|
||
| // Clear input fields | ||
| txe_teamMemberFirstName.Text = ""; | ||
| txe_teamMemberLastName.Text = ""; | ||
| txe_teamMemberEmail.Text = ""; | ||
| } | ||
|
|
||
|
|
||
| /*! | ||
| * Detect delete button being clicked | ||
| * @param sender (Object) the sender object created by the event | ||
| * @param e (EventArgs) the arguments passed into the event | ||
| */ | ||
| private async void DeleteButton_Clicked(object sender, EventArgs e) | ||
| { | ||
| if (ltv_teamMembers.SelectedItem == null) | ||
| { | ||
| await DisplayAlert("No TeamMember Selected", "Select the teamMember you want to delete from the list", "OK"); | ||
| return; | ||
| } | ||
|
|
||
| TeamMember selectedTeamMember = (TeamMember)ltv_teamMembers.SelectedItem; | ||
|
|
||
| await teamMemberService.DeleteTeamMember(selectedTeamMember); | ||
| teamMembers.Remove(selectedTeamMember); | ||
|
|
||
| // Clear input fields | ||
| txe_teamMemberFirstName.Text = ""; | ||
| txe_teamMemberLastName.Text = ""; | ||
| txe_teamMemberEmail.Text = ""; | ||
|
|
||
| ltv_teamMembers.SelectedItem = null; | ||
| } | ||
|
|
||
|
|
||
| /*! | ||
| * Detect all items selected in list view | ||
| * @param sender (Object) the sender object created by the event | ||
| * @param e (SelectedItemChangedEventArgs) the arguments passed into the event | ||
| */ | ||
| private void ltv_teamMembers_ItemSelected(object sender, SelectedItemChangedEventArgs e) | ||
| { | ||
| TeamMember selectedTeamMember = e.SelectedItem as TeamMember; | ||
| if (selectedTeamMember == null) return; | ||
|
|
||
| txe_teamMemberFirstName.Text = selectedTeamMember.Firstname; | ||
| txe_teamMemberLastName.Text = selectedTeamMember.Lastname; | ||
| txe_teamMemberEmail.Text = selectedTeamMember.Email; | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this violates dry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it also violates SRP because it should be in a different method