Skip to content

Commit

Permalink
add monapi to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Kraemer committed Jul 28, 2015
1 parent 6e5290b commit 1372e96
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
6 changes: 1 addition & 5 deletions MONI/Data/MonapiJSONExporter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace MONI.Data
Expand Down
9 changes: 8 additions & 1 deletion MONI/Data/MoniSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ public class MoniSettings
public WorkDayParserSettings ParserSettings { get; set; }
public MainSettings MainSettings { get; set; }
public static MoniSettings GetEmptySettings() {
var ms = new MainSettings { DataDirectory = AppDomain.CurrentDomain.BaseDirectory, MonlistExecutablePath = @"n:\Monlist2\Monlist2.exe", ProjectNumberFilePath = @"n:\Monlist2\projekte.txt", UpdateInfoURL = "http://mtools/moni_updates.json", ShowMonthList = true};
var ms = new MainSettings {
DataDirectory = AppDomain.CurrentDomain.BaseDirectory,
MonlistExecutablePath = @"n:\Monlist2\Monlist2.exe",
ProjectNumberFilePath = @"n:\Monlist2\projekte.txt",
UpdateInfoURL = "http://mtools/moni_updates.json",
ShowMonthList = true,
MonApiUrl = "https://usability.inform-ac.com/monapi"
};
return new MoniSettings { ParserSettings = new WorkDayParserSettings(), MainSettings = ms };
}

Expand Down
1 change: 0 additions & 1 deletion MONI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
Expand Down
27 changes: 25 additions & 2 deletions MONI/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -385,9 +387,29 @@
Margin="2"
IsEnabled="{Binding IsChecked, ElementName=autoPause, Mode=OneWay}"
Text="{Binding ParserSettings.DayBreakDurationInMinutes, UpdateSourceTrigger=PropertyChanged}" />

<Label Grid.Column="0"
Grid.Row="14"
IsEnabled="{Binding IsChecked, ElementName=autoPause, Mode=OneWay}">
MonAPI-URL
</Label>
<TextBox Grid.Column="1"
Grid.Row="14"
Margin="2"
Text="{Binding MainSettings.MonApiUrl, UpdateSourceTrigger=PropertyChanged}" />

<Label Grid.Column="0"
Grid.Row="15">
MonAPI benutzen
</Label>
<CheckBox Grid.Column="1"
Grid.Row="15"
Margin="2"
VerticalAlignment="Center"
IsChecked="{Binding MainSettings.UseMonApi, UpdateSourceTrigger=PropertyChanged}" />

<UniformGrid Grid.Column="0"
Grid.Row="14"
Grid.Row="16"
Grid.ColumnSpan="2"
VerticalAlignment="Bottom"
Columns="2">
Expand Down Expand Up @@ -902,7 +924,8 @@
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Width="5"
Background="Transparent" />
Background="Transparent"
Focusable="False"/>

<!-- shortcuts -->
<StackPanel x:Name="shortCutHeader"
Expand Down
7 changes: 3 additions & 4 deletions MONI/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public MainView() {

private void CheckForMonlist() {
var mlp = Utils.PatchFilePath(this.ViewModel.Settings.MainSettings.MonlistExecutablePath);
this.OpenMonlist.IsEnabled = !(string.IsNullOrWhiteSpace(mlp) || !File.Exists(mlp));
this.OpenMonlist.IsEnabled = !(string.IsNullOrWhiteSpace(mlp) || !File.Exists(mlp)) || (this.ViewModel.Settings.MainSettings.UseMonApi && !string.IsNullOrWhiteSpace(this.ViewModel.Settings.MainSettings.MonApiUrl));
}

public MainViewModel ViewModel { get; set; }
Expand Down Expand Up @@ -299,17 +299,16 @@ private void PasswordOK_OnClick(object sender, RoutedEventArgs e) {
Process.Start(this.ViewModel.Settings.MainSettings.MonlistExecutablePath, args);
}
else {
var usernumberAsInt = 0;
int usernumberAsInt;
if (int.TryParse(this.ViewModel.Settings.MainSettings.MonlistEmployeeNumber, out usernumberAsInt)) {
var me = new MonapiJSONExporter(usernumberAsInt);
var jsonData = me.Export(this.ViewModel.WorkMonth);
var cli = new WebClient();
cli.Headers[HttpRequestHeader.ContentType] = "application/json";
string _auth = string.Format("{0}:{1}", this.ViewModel.Settings.MainSettings.MonlistEmployeeNumber, password);
string _auth = string.Format("{0}:{1}", usernumberAsInt, password);
string _enc = Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth));
string _cred = string.Format("{0} {1}", "Basic", _enc);
cli.Headers[HttpRequestHeader.Authorization] = _cred;
this.ViewModel.Settings.MainSettings.MonApiUrl = "http://mbp-jdiehl:3001/import";
try {
string response = cli.UploadString(this.ViewModel.Settings.MainSettings.MonApiUrl, jsonData);
logger.Info("Response from sending data to MonApi: {0}", response);
Expand Down

0 comments on commit 1372e96

Please sign in to comment.