Skip to content

Commit

Permalink
The basic terminal functionality works, now onto the cosmetics
Browse files Browse the repository at this point in the history
This is for issue #100.
  • Loading branch information
haefele committed Nov 16, 2016
1 parent 5b8265d commit 7f1f7b9
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,15 @@ public static void SetApplicationTheme(this IApplicationStateService self, Eleme
{
self.Set("ApplicationTheme", theme, UwCore.Services.ApplicationState.ApplicationState.Roaming);
}

public static string GetCompanyId(this IApplicationStateService self)
{
return self.Get<string>("CompanyId", UwCore.Services.ApplicationState.ApplicationState.Roaming) ?? string.Empty;
}

public static void SetCompanyId(this IApplicationStateService self, string companyId)
{
self.Set("CompanyId", companyId, UwCore.Services.ApplicationState.ApplicationState.Roaming);
}
}
}
3 changes: 2 additions & 1 deletion src/CTime2.Core/Services/CTime/CTimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public async Task<IList<Time>> GetTimes(string employeeGuid, DateTime start, Dat
}
}

public async Task SaveTimer(string employeeGuid, DateTime time, string companyId, TimeState state, bool withGeolocation)
public async Task SaveTimer(string employeeGuid, string rfidKey, DateTime time, string companyId, TimeState state, bool withGeolocation)
{
try
{
Expand All @@ -150,6 +150,7 @@ public async Task SaveTimer(string employeeGuid, DateTime time, string companyId
{"TimerTime", time.ToString("yyyy-MM-dd HH:mm:ss")},
{"EmployeeGUID", employeeGuid},
{"GUID", companyId},
{"RFID", rfidKey},
{"lat", location?.Position.Latitude.ToString(CultureInfo.InvariantCulture) ?? string.Empty },
{"long", location?.Position.Longitude.ToString(CultureInfo.InvariantCulture) ?? string.Empty }
});
Expand Down
4 changes: 2 additions & 2 deletions src/CTime2.Core/Services/CTime/ICTimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ICTimeService
{
Task<User> Login(string emailAddress, string password);
Task<IList<Time>> GetTimes(string employeeGuid, DateTime start, DateTime end);
Task SaveTimer(string employeeGuid, DateTime time, string companyId, TimeState state, bool withGeolocation);
Task SaveTimer(string employeeGuid, string rfidKey, DateTime time, string companyId, TimeState state, bool withGeolocation);
Task<Time> GetCurrentTime(string employeeGuid);
Task<IList<AttendingUser>> GetAttendingUsers(string companyId, byte[] defaultImage);
}
Expand All @@ -18,7 +18,7 @@ public static class CTimeServiceExtensions
{
public static async Task SaveTimer(this ICTimeService self, User user, TimeState state)
{
await self.SaveTimer(user.Id, DateTime.Now, user.CompanyId, state, user.SupportsGeoLocation);
await self.SaveTimer(user.Id, string.Empty, DateTime.Now, user.CompanyId, state, user.SupportsGeoLocation);
}

public static async Task<bool> IsCurrentlyCheckedIn(this ICTimeService self, string employeeGuid)
Expand Down
7 changes: 7 additions & 0 deletions src/CTime2/Views/Settings/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@
</StackPanel>
</controls:SettingsItem>
</controls:SettingsGroup>
<controls:SettingsGroup Header="Terminal"
Description="Um diese App an einem Terminal zum Stempeln mit RFID-Chips zu verwenden, musst du deine Firmen-ID von c-time hier eintragen.">
<controls:SettingsItem Description="Firmen-ID">
<TextBox Text="{Binding CompanyId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Width="300" />
</controls:SettingsItem>
</controls:SettingsGroup>
</StackPanel>
</ScrollViewer>
</Page>
14 changes: 14 additions & 0 deletions src/CTime2/Views/Settings/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SettingsViewModel : ReactiveScreen
private TimeSpan _selectedBreakTime;
private BandState _state;
private ElementTheme _theme;
private string _companyId;

public ReactiveObservableCollection<TimeSpan> WorkTimes
{
Expand Down Expand Up @@ -71,6 +72,12 @@ public ElementTheme Theme
set { this.RaiseAndSetIfChanged(ref this._theme, value); }
}

public string CompanyId
{
get { return this._companyId; }
set { this.RaiseAndSetIfChanged(ref this._companyId, value); }
}

public UwCoreCommand<Unit> Reload { get; }
public UwCoreCommand<Unit> RememberLogin { get; }
public UwCoreCommand<Unit> ToggleBandTile { get; }
Expand Down Expand Up @@ -109,6 +116,7 @@ public SettingsViewModel(IBiometricsService biometricsService, IApplicationState
this.Theme = this._applicationStateService.GetApplicationTheme();
this.SelectedWorkTime = this._applicationStateService.GetWorkDayHours();
this.SelectedBreakTime = this._applicationStateService.GetWorkDayBreak();
this.CompanyId = this._applicationStateService.GetCompanyId();

this.WhenAnyValue(f => f.Theme)
.Subscribe(theme =>
Expand All @@ -129,6 +137,12 @@ public SettingsViewModel(IBiometricsService biometricsService, IApplicationState
this._applicationStateService.SetWorkDayBreak(breakTime);
});

this.WhenAnyValue(f => f.CompanyId)
.Subscribe(companyId =>
{
this._applicationStateService.SetCompanyId(companyId);
});

this.DisplayName = CTime2Resources.Get("Navigation.Settings");

this.WorkTimes = new ReactiveObservableCollection<TimeSpan>(Enumerable
Expand Down
17 changes: 16 additions & 1 deletion src/CTime2/Views/Terminal/TerminalView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CTime2.Views.Terminal"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:behaviors="using:UwCore.Behaviors"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Text="Terminal!" Style="{StaticResource TitleTextBlockStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" />

<TextBox x:Name="RfidReaderTextBox"
Text="{Binding RfidKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Opacity="0"
IsHitTestVisible="False">
<interactivity:Interaction.Behaviors>
<behaviors:KeyTriggerBehavior Key="Enter">
<core:InvokeCommandAction Command="{x:Bind ViewModel.Stamp}" />
</behaviors:KeyTriggerBehavior>
</interactivity:Interaction.Behaviors>
</TextBox>

</Grid>
</Page>
33 changes: 17 additions & 16 deletions src/CTime2/Views/Terminal/TerminalView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using System.Threading;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace CTime2.Views.Terminal
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class TerminalView : Page
{
private readonly Timer _focusTextBoxTimer;

public TerminalViewModel ViewModel => this.DataContext as TerminalViewModel;

public TerminalView()
{
this.InitializeComponent();

this._focusTextBoxTimer = new Timer(this.TryFocusTextBox, null, TimeSpan.Zero, TimeSpan.FromSeconds(0.5));
}

private void TryFocusTextBox(object state)
{
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
this.RfidReaderTextBox.Focus(FocusState.Programmatic);

}).AsTask().Wait();
}
}
}
55 changes: 53 additions & 2 deletions src/CTime2/Views/Terminal/TerminalViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
using Caliburn.Micro.ReactiveUI;
using System;
using System.Diagnostics;
using System.Reactive;
using System.Threading.Tasks;
using Caliburn.Micro.ReactiveUI;
using CTime2.Core.Data;
using CTime2.Core.Services.ApplicationState;
using CTime2.Core.Services.CTime;
using ReactiveUI;
using UwCore;
using UwCore.Common;
using UwCore.Services.ApplicationState;

namespace CTime2.Views.Terminal
{
public class TerminalViewModel : ReactiveScreen
{

private readonly ICTimeService _cTimeService;
private readonly IApplicationStateService _applicationStateService;

private string _rfidKey;

public string RfidKey
{
get { return this._rfidKey; }
set { this.RaiseAndSetIfChanged(ref this._rfidKey, value); }
}

public UwCoreCommand<Unit> Stamp { get; }

public TerminalViewModel(ICTimeService cTimeService, IApplicationStateService applicationStateService)
{
Guard.NotNull(cTimeService, nameof(cTimeService));
Guard.NotNull(applicationStateService, nameof(applicationStateService));

this._cTimeService = cTimeService;
this._applicationStateService = applicationStateService;

var canStamp = this.WhenAnyValue(f => f.RfidKey, (string rfidKey) => string.IsNullOrWhiteSpace(rfidKey) == false);
this.Stamp = UwCoreCommand.Create(canStamp, this.StampImpl)
.HandleExceptions()
.ShowLoadingOverlay("Stempeln...");
}

private async Task StampImpl()
{
Debug.WriteLine(this.RfidKey);

await this._cTimeService.SaveTimer(
string.Empty,
this.RfidKey,
DateTime.Now,
this._applicationStateService.GetCompanyId(),
TimeState.Entered,
true);

this.RfidKey = string.Empty;
}
}
}

0 comments on commit 7f1f7b9

Please sign in to comment.