Skip to content

Commit

Permalink
Release April (#14)
Browse files Browse the repository at this point in the history
* Support to workspaces
* Support to HaraFeature (easy log appointment)
  • Loading branch information
fcatae authored Apr 28, 2017
1 parent 5b7a698 commit 21911ce
Show file tree
Hide file tree
Showing 18 changed files with 2,833 additions and 19 deletions.
19 changes: 19 additions & 0 deletions src/Arda.Main/Controllers/AppointmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public IActionResult Add()
return View();
}

public IActionResult AddSimple([FromQuery]string wbid)
{
ViewBag.Guid = Util.GenerateNewGuid();
ViewBag.WBID = wbid;
return View();
}

[HttpPost]
public async Task<HttpResponseMessage> AddAppointment(AppointmentViewModel appointment)
{
Expand All @@ -35,6 +42,18 @@ public async Task<HttpResponseMessage> AddAppointment(AppointmentViewModel appoi
Decimal.TryParse(Request.Form["_AppointmentTE"], NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, new CultureInfo("pt-BR"), out TE);
appointment._AppointmentTE = TE;

//DateTime date;
//if(DateTime.TryParse(Request.Form["_AppointmentDate"], new CultureInfo("pt-BR"), DateTimeStyles.AllowWhiteSpaces, out date))
//{
// appointment._AppointmentDate = date;
//}

if (appointment._AppointmentDate == DateTime.MinValue)
{
// there can be some problems due to date formatting
throw new Exception("invalid date range");
}

var uniqueName = HttpContext.User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value;

var responseAboutAdd = await Util.ConnectToRemoteService(HttpMethod.Post, Util.KanbanURL + "api/appointment/add", uniqueName, "", appointment);
Expand Down
46 changes: 46 additions & 0 deletions src/Arda.Main/Controllers/WorkController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Arda.Common.Utils;
using System.Net.Http;
using Arda.Main.Utils;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using System.Net.Http.Headers;
using Arda.Main.ViewModels;
using Newtonsoft.Json;

// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace Arda.Main.Controllers
{
[Authorize]
public class WorkController : Controller
{
public IActionResult Index()
{
var user = User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value;

ViewBag.User = user;

UsageTelemetry.Track(user, ArdaUsage.Work_Index);

return View();
}

[HttpGet("[controller]/{workspace}")]
public IActionResult Workspace(string workspace)
{
var user = User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value;

ViewBag.User = user;
ViewBag.Title = workspace.ToUpper();
ViewBag.Work = workspace.ToLower();

UsageTelemetry.Track(user, ArdaUsage.Work_Index);

return View();
}
}
}
64 changes: 57 additions & 7 deletions src/Arda.Main/Controllers/WorkloadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ public async Task<JsonResult> ListBacklogsByUser([FromQuery] string User)
return Json(dados);
}


[HttpGet]
public async Task<JsonResult> ListWorkloadsByUser([FromQuery] string User)
public async Task<JsonResult> ListWorkloadsByUser([FromQuery] string User, [FromQuery] string Tag)
{
if( Tag != null && Tag != "" )
{
return await ListWorkloadsByWorkspace(Tag);
}
return await ListWorkloads(User);
}

private async Task<JsonResult> ListWorkloads(string User)
{
var loggedUser = HttpContext.User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value;

Expand Down Expand Up @@ -79,9 +89,33 @@ public async Task<JsonResult> ListWorkloadsByUser([FromQuery] string User)

return Json(dados);
}
private async Task<JsonResult> ListWorkloadsByWorkspace(string workspace)
{
var workloads = new List<string>();

var existentWorkloads = await Util.ConnectToRemoteService<List<WorkloadsByUserViewModel>>(HttpMethod.Get, Util.KanbanURL + "api/workload2/listtag?tag=" + workspace,"","");

var dados = existentWorkloads.Where(x => x._WorkloadIsWorkload == true)
.Select(x => new {
id = x._WorkloadID,
title = x._WorkloadTitle,
start = x._WorkloadStartDate.ToString("dd/MM/yyyy"),
end = x._WorkloadEndDate.ToString("dd/MM/yyyy"),
hours = x._WorkloadHours,
attachments = x._WorkloadAttachments,
tag = x._WorkloadExpertise,
status = x._WorkloadStatus,
users = x._WorkloadUsers,
textual = x._WorkloadTitle + " (Started in " + x._WorkloadStartDate.ToString("dd/MM/yyyy") + " and Ending in " + x._WorkloadEndDate.ToString("dd/MM/yyyy") + ", with " + x._WorkloadHours + " hours spent on this."
})
.Distinct()
.ToList();

return Json(dados);
}

[HttpPost]
public async Task<HttpResponseMessage> Add(ICollection<IFormFile> WBFiles, WorkloadViewModel workload)
public async Task<HttpResponseMessage> Add(ICollection<IFormFile> WBFiles, WorkloadViewModel2 workload)
{
//Owner:
var uniqueName = HttpContext.User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value;
Expand All @@ -95,19 +129,35 @@ public async Task<HttpResponseMessage> Add(ICollection<IFormFile> WBFiles, Workl
//Adds the file lists to the workload object:
workload.WBFilesList = fileList;
}

//string api_workload_add;
//if (workload.Tag != null && workload.Tag != "")
//{
// api_workload_add = $"api/workload2/{workload.Tag}/add";
//}
//else
//{
// api_workload_add = "api/workload/add";
//}

var response = await Util.ConnectToRemoteService(HttpMethod.Post, Util.KanbanURL + "api/workload/add", uniqueName, "", workload);

UsageTelemetry.Track(uniqueName, ArdaUsage.Workload_Add);

if (response.IsSuccessStatusCode)
{
return new HttpResponseMessage(HttpStatusCode.OK);
}
else
if (!response.IsSuccessStatusCode)
{
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}

string tag = workload.Tag;
string wbid = workload.WBID.ToString();

if (workload.Tag != null && workload.Tag != "")
{
var strresp = await Util.ConnectToRemoteServiceString(HttpMethod.Post, Util.KanbanURL + $"api/workload2/{tag}/assign/{wbid}", uniqueName, "");
}

return new HttpResponseMessage(HttpStatusCode.OK);
}

[HttpPost]
Expand Down
3 changes: 2 additions & 1 deletion src/Arda.Main/UsageTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum ArdaUsage
Appointment_Add,
Report_Show,
Dashboard_Archive,
Archive_User
Archive_User,
Work_Index
}

public static class UsageTelemetry
Expand Down
39 changes: 29 additions & 10 deletions src/Arda.Main/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,36 @@ public static string GetString(byte[] obj)
return Encoding.UTF8.GetString(obj);
}

public static async Task<T> ConnectToRemoteService<T>(HttpMethod method, string url, string uniqueName, string code)
public static async Task<string> ClientSendAsync(HttpMethod method, string url, string uniqueName, string code)
{
var client = new HttpClient();
var request = new HttpRequestMessage(method, url);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{
var client = new HttpClient();
var request = new HttpRequestMessage(method, url);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

request.Headers.Add("unique_name", uniqueName);
request.Headers.Add("code", code);
request.Headers.Add("unique_name", uniqueName);
request.Headers.Add("code", code);

var response = await client.SendAsync(request);

if (!response.IsSuccessStatusCode)
{
throw new InvalidOperationException("Invalid HTTP code: " + response.StatusCode);
}

return await response.Content.ReadAsStringAsync();
}
catch (Exception httpExc)
{
throw new Exception("Could not contact endpoint: " + url, httpExc);
}
}

public static async Task<T> ConnectToRemoteService<T>(HttpMethod method, string url, string uniqueName, string code)
{
var responseJson = await ClientSendAsync(method, url, uniqueName, code);

var responseRaw = await client.SendAsync(request);
var responseJson = responseRaw.Content.ReadAsStringAsync().Result;
var responseConverted = JsonConvert.DeserializeObject<T>(responseJson);

return responseConverted;
Expand All @@ -144,11 +163,11 @@ public static async Task<string> ConnectToRemoteServiceString(HttpMethod method,

var responseSend = await client.SendAsync(request);

if(responseSend.IsSuccessStatusCode)
if (responseSend.IsSuccessStatusCode)
{
var responseStr = await responseSend.Content.ReadAsStringAsync();

if( responseStr != "" )
if (responseStr != "")
return responseStr;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Arda.Main/ViewModels/WorkloadViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

namespace Arda.Main.ViewModels
{
public class WorkloadViewModel2 : WorkloadViewModel
{
public string Tag { get; set; }
}

public class WorkloadViewModel
{
public Guid WBID { get; set; }
Expand Down
123 changes: 123 additions & 0 deletions src/Arda.Main/Views/Appointment/AddSimple.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
@{
Layout = "~/Views/Shared/_LayoutEmpty.cshtml";
}
<section class="concontainer-fluid">
<div id="message">
<!-- Message dynamically inputed here -->
</div>
<div class="col-xs-12">
<div class="row">

@*<header class="ctn-header-dashboard">
<!-- Title -->
<div class="col-xs-12 col-lg-3 col-md-4">
<h2>
Work Appointment
</h2>
<p>Adding a new work appointment to specific workload</p>
</div>
<!-- Some information -->
<div class="col-xs-12 col-lg-3 col-md-4">
</div>
<!-- Clear some garbage -->
<div class="clearfix"></div>
</header>*@

<div style="margin-top:20px;">

<div class="col-xs-12" style="border-right:1px solid #efefef;">

<form id="form-simpleadd-appointment" role="form" data-toggle="validation">

<!-- Simple: Hidden from user because it is too internal -->
<div class="form-group" hidden>
<label for="_AppointmentID">Code:</label>
<input type="text" class="form-control" id="_AppointmentID" name="_AppointmentID" value="@ViewBag.Guid" readonly>
</div>

<!-- Simple: Hidden from user because it is too obvious -->
<div class="form-group" hidden>
<label for="_AppointmentUserName">Appointment to:</label>
<input type="text" class="form-control" id="_AppointmentUserName" name="_AppointmentUserName" value="@User.Claims.First(claim => claim.Type == "name").Value" readonly />
<input type="hidden" id="_AppointmentUserUniqueName" name="_AppointmentUserUniqueName" value="@User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value" />
</div>

<div class="form-group">
<label for="_WorkloadTitle">Workload:</label>
<input type="hidden" name="_AppointmentWorkloadWBID" id="_AppointmentWorkloadWBID" value="@ViewBag.WBID" />
<input id="_WorkloadTitle" name="_WorkloadTitle" type="text" class="form-control" readonly value="@ViewBag.WBID">
</div>

<div class="row">
<div class="col-md-4" id="sandbox-container">
<div class="form-group">
<label for="_AppointmentDate">Appointment date:</label>
<div class="input-group date">
<!-- Add Simple -->
<input type="text" id="_AppointmentDate" name="_AppointmentDate" class="form-control" value="@DateTime.Now.ToString("MM/dd/yyyy")">
<span class="input-group-addon"><i class="fa fa-calendar-check-o" aria-hidden="true"></i></span>
</div>
</div>
</div>

<div class="col-md-4">
<div class="form-group">
<label for="_AppointmentHoursDispensed">Hours dispensed (on refered date):</label>
<select id="_AppointmentHoursDispensed" name="_AppointmentHoursDispensed" class="form-control">
<option value="0" selected>- SELECT -</option>
@for (int i = 1; i <= 24; i++)
{
<option value="@i">@i</option>
}
</select>
</div>
</div>

<div class="col-md-4">
<!-- Hide from the user -->
@*<div class="form-group" hidden>
<label for="_AppointmentTE">T&E (if applyable):</label>
<input type="text" id="_AppointmentTE" name="_AppointmentTE" class="form-control" placeholder="R$ 0,00" />
</div>*@
</div>
</div>

<div class="form-group">
<label for="_AppointmentComment">Any comment about this activity?</label>
<textarea class="form-control" rows="5" id="_AppointmentComment" name="_AppointmentComment"></textarea>
</div>

<button type="submit" class="btn btn-info" id="btnAddAppointment">
<i class='fa fa-floppy-o' aria-hidden='true'></i> Create
</button>

</form>



</div>
<!-- No need to create a new -->
@*<div class="col-xs-6 col-md-4">
<h3>
New work appointment
</h3>
<p>
To add a new work appointment, please click on button bellow. <br />
<div class="data-sorting-buttons">
<a asp-controller="Appointment" asp-action="Add" class="ds-button-update"><i class="fa fa-plus" aria-hidden="true"></i> Add</a>
</div>
</p>
</div>*@
</div>

</div>
</div>
</section>


2 changes: 1 addition & 1 deletion src/Arda.Main/Views/Dashboard/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
}
}
<!-- Workload Modal -->
@await Html.PartialAsync("_WorkloadModal")
@await Html.PartialAsync("_WorkloadModal2")

<script>
//Global Variables:
Expand Down
Loading

0 comments on commit 21911ce

Please sign in to comment.