Skip to content
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

The sidebar should be separate for each worker #210

Merged
merged 13 commits into from
Oct 19, 2024
22 changes: 11 additions & 11 deletions CheckDrive.Web/CheckDrive.Web/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public IActionResult Index()
{
if (HttpContext.Request.Cookies.TryGetValue("tasty-cookies", out _))
{
string token = HttpContext.Request.Cookies["tasty-cookies"];
var tokenHandler = new JwtSecurityTokenHandler();
var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;
if (jwtToken == null)
{
return RedirectToAction("Login", "Account");
}
var roleId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.Role).Value;
var accountId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.NameIdentifier).Value;
string token = HttpContext.Request.Cookies["tasty-cookies"];
var tokenHandler = new JwtSecurityTokenHandler();
var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;
if (jwtToken == null)
{
return RedirectToAction("Login", "Account");
}
var roleId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.Role).Value;
var accountId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.NameIdentifier).Value;
int accountIds = Int32.Parse(accountId);

switch (roleId)
{
case "1":
TempData["UserName"] = _accountDataStore.GetAccountAsync(accountIds)
.Result.FirstName;
TempData.Keep("UserName");
TempData.Keep("UserName");
return RedirectToAction("Index", "Dashboard");
case "3":
TempData["AccountId"] = accountId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using CheckDrive.Web.Stores.MechanicAcceptances;
using CheckDrive.Web.Stores.MechanicHandovers;
using CheckDrive.Web.Stores.Mechanics;
using CheckDrive.Web.Stores.Menu;
using CheckDrive.Web.Stores.MockDashboard;
using CheckDrive.Web.Stores.OilMarks;
using CheckDrive.Web.Stores.OperatorReviews;
Expand Down Expand Up @@ -42,7 +43,8 @@ public static IServiceCollection ConfigureDataStores(this IServiceCollection ser
services.AddScoped<IDashboardStore, DashboardStore>();
services.AddScoped<IMockDashboardStore, MockDashboardStore>();
services.AddScoped<IUserDataStore, UserDataStore>();

services.AddScoped<IMenuService, MenuService>();
services.AddScoped<ICurrentUserService, CurrentUserService>();
return services;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text;
using CheckDrive.ApiContracts.DoctorReview;
using CheckDrive.Web.Models;
using CheckDrive.Web.Responses;
using CheckDrive.Web.Service;
using Newtonsoft.Json;
Expand Down
6 changes: 6 additions & 0 deletions CheckDrive.Web/CheckDrive.Web/Stores/Menu/IMenuService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CheckDrive.Web.Stores.Menu;

public interface IMenuService
{
List<Object> GetMenuItems(string role);
}
179 changes: 179 additions & 0 deletions CheckDrive.Web/CheckDrive.Web/Stores/Menu/MenuService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
namespace CheckDrive.Web.Stores.Menu;

public class MenuService : IMenuService
{
public List<Object> GetMenuItems(string role)
{
List<Object> menuItems = new List<Object>();

if(role=="1")
{
menuItems.Add(new
{
text = "Dashboard",
iconCss = "fa-solid fa-home",
url = "/dashboard",
});

menuItems.Add(new
{
text = "Qarzlar",
iconCss = "fa-solid fa-file-invoice-dollar",
url = "/#",
});

menuItems.Add(new
{
text = "Umumiy",
separator = true,
});

menuItems.Add(new
{
text = "Ishchilar",
iconCss = "fas fa-users",
url = "/accounts"
});

menuItems.Add(new
{
text = "Avtomobillar",
iconCss = "fas fa-car",
url = "/cars"
});

menuItems.Add(new
{
text = "Yoqilg'ilar",
iconCss = "fa-solid fa-gas-pump",
url = "/#"
});

menuItems.Add(new
{
text = "Tekshiruvlar",
separator = true,
});

menuItems.Add(new
{
text = "Shifokor",
iconCss = "fa-solid fa-briefcase-medical",
url = "/doctorreviews"
});

menuItems.Add(new
{
text = "Mexanik (Topshirish)",
iconCss = "fa-solid fa-tools",
url = "/mechanichandovers"
});

menuItems.Add(new
{
text = "Operator",
iconCss = "fa-solid fa-headset",
url = "/OperatorReviews"
});

menuItems.Add(new
{
text = "Mexanik (Qabul qilish)",
iconCss = "fa-solid fa-car-on",
url = "/mechanicacceptances"
});

menuItems.Add(new
{
text = "Dispetcher",
iconCss = "fa-solid fa-user-gear",
url = "/DispatcherReviews"
});
}
else if (role == "3")
{
menuItems.Add(new
{
text = "Asosiy sahifa",
iconCss = "fa-solid fa-house",
url = "/doctorreviews/personalindex"
});

menuItems.Add(new
{
text = "Tarixni ko'rish",
iconCss = "fa-solid fa-clock-rotate-left",
url = "/doctorreviews/historyindexforpersonalpage"
});
}
else if (role == "4")
{
menuItems.Add(new
{
text = "Asosiy sahifa",
iconCss = "fa-solid fa-house",
url = "/operatorreviews/personalindex"
});

menuItems.Add(new
{
text = " Hisobot",
iconCss = "fa-regular fa-clipboard",
url = "/operatorreviews/reportindexforpersonalpage"
});

menuItems.Add(new
{
text = "Tarixni ko'rish",
iconCss = "fa-solid fa-clock-rotate-left",
url = "/operatorreviews/historyindexforpersonalpage"
});
}
else if (role == "5")
{
menuItems.Add(new
{
text = "Asosiy sahifa",
iconCss = "fa-solid fa-house",
url = "/dispatcherreviews/personalindex"
});

menuItems.Add(new
{
text = "Tarixni ko'rish",
iconCss = "fa-solid fa-clock-rotate-left",
url = "/dispatcherreviews/historyindexforpersonalpage"
});
}
else if (role == "6")
{

menuItems.Add(new
{
id = "handoversItem",
text = "Topshirish",
iconCss = "fa-solid fa-tools",
url = "/mechanichandovers/personalindex"
});


menuItems.Add(new
{
id="acceptancesItem",
text = "Qabul qilish",
iconCss = "fa-solid fa-car-on",
url = "/mechanicacceptances/personalindex"
});

menuItems.Add(new
{
id="historyItem",
text = "Tarixni ko'rish",
iconCss = "fa-solid fa-clock-rotate-left",
url = "/mechanicacceptances/historyindexforpersonalpage"
});
}

return menuItems;
}
}
32 changes: 32 additions & 0 deletions CheckDrive.Web/CheckDrive.Web/Stores/User/CurrentUserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;

namespace CheckDrive.Web.Stores.User;

public class CurrentUserService:ICurrentUserService
{
private readonly IHttpContextAccessor _httpContextAccessor;

public CurrentUserService(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}

public string GetRole()
{
var httpContext = _httpContextAccessor.HttpContext;

if (httpContext == null || !httpContext.Request.Cookies.ContainsKey("tasty-cookies"))
{
return null;
}

string token = httpContext.Request.Cookies["tasty-cookies"];
var tokenHandler = new JwtSecurityTokenHandler();
var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;

var roleId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.Role).Value;

return roleId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;

namespace CheckDrive.Web.Stores.User;

public interface ICurrentUserService
{
string GetRole();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,9 @@
@{
ViewData["Title"] = "HistoryIndexForPersonalPage";
Layout = "~/Views/Shared/_PersonalLayout.cshtml";
string activeTab = "HistoryIndexForPersonalPage";
}

<div class="container-fluid py-2 px-4 d-flex justify-content-end">
<div class="d-flex align-items-center">
<button class="logout-btn" type="button" onclick="window.location.href='@Url.Action("Login", "Auth")'">
<span class="logout-icon">
<i class="fas fa-sign-out-alt"></i>
</span>
Chiqish
</button>
</div>
</div>
<div class="container mt-5" style="max-width: 100%;">
<div class="mb-4">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link @(activeTab == "PersonalIndex" ? "active" : "")" href="@Url.Action("PersonalIndex", "DispatcherReviews")">Asosiy sahifa</a>
</li>
<li class="nav-item">
<a class="nav-link @(activeTab == "HistoryIndexForPersonalPage" ? "active" : "")" href="@Url.Action("HistoryIndexForPersonalPage", "DispatcherReviews")">Tarixni ko'rish</a>
</li>
</ul>
</div>
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover paper-shadow" style="width: 100%;">
<thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,10 @@
@{
ViewData["Title"] = "PersonalIndex";
Layout = "~/Views/Shared/_PersonalLayout.cshtml";
string activeTab = "PersonalIndex";
}
<div class="container-fluid py-2 px-4 d-flex justify-content-end">
<div class="d-flex align-items-center">
<button class="logout-btn" type="button" onclick="window.location.href='@Url.Action("Login", "Auth")'">
<span class="logout-icon">
<i class="fas fa-sign-out-alt"></i>
</span>
Chiqish
</button>
</div>
</div>

<div class="container mt-5" style="max-width: 100%;">
<div class="mb-4 d-flex justify-content-between align-items-center">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link @(activeTab == "PersonalIndex" ? "active" : "")" href="@Url.Action("PersonalIndex", "DispatcherReviews")">Asosiy sahifa</a>
</li>
<li class="nav-item">
<a class="nav-link @(activeTab == "HistoryIndexForPersonalPage" ? "active" : "")" href="@Url.Action("HistoryIndexForPersonalPage", "DispatcherReviews")">Tarixni ko'rish</a>
</li>
</ul>
<div class="gap-2">
<a class="btn btn-primary" href="@Url.Action("CarHistoryIndex", "Cars")">Moshina tarixi</a>
<!-- Dropdown Menu for File Download -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,11 @@
@{
ViewData["Title"] = "HistoryIndexForPersonalPage";
Layout = "~/Views/Shared/_PersonalLayout.cshtml";
string activeTab = "HistoryIndexForPersonalPage";
}

<div class="container-fluid py-2 px-4 d-flex justify-content-end">
<div class="d-flex align-items-center">
<button class="logout-btn" type="button" onclick="window.location.href='@Url.Action("Login", "Auth")'">
<span class="logout-icon">
<i class="fas fa-sign-out-alt"></i>
</span>
Chiqish
</button>
</div>
</div>
<form asp-controller="DoctorReviews" asp-action="HistoryIndexForPersonalPage">
<div class="container mt-5 ">
<div class="mb-4">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link @(activeTab == "PersonalIndex" ? "active" : "")" href="@Url.Action("PersonalIndex", "DoctorReviews")">Asosiy sahifa</a>
</li>
<li class="nav-item">
<a class="nav-link @(activeTab == "HistoryIndexForPersonalPage" ? "active" : "")" href="@Url.Action("HistoryIndexForPersonalPage", "DoctorReviews")">Tarixni ko'rish</a>
</li>
</ul>
</div>

<div class="row justify-content-between align-items-center mb-4">
<!-- Search -->
<div class="col-md-4">
Expand Down
Loading