connect tarball to db_mms. improve sorting, filtering and search
This commit is contained in:
parent
6d7a04ae7c
commit
58434ccc1d
@ -1,7 +1,10 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PSTW_CentralSystem.DBContext;
|
||||
using PSTW_CentralSystem.Models;
|
||||
using PSTW_CentralSystem.Areas.MMS;
|
||||
using System.Linq;
|
||||
using QuestPDF.Fluent;
|
||||
|
||||
namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
@ -11,24 +14,64 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
//[Authorize(Policy = "RoleModulePolicy")]
|
||||
public class MarineController : Controller
|
||||
{
|
||||
private readonly MMSSystemContext _context;
|
||||
public MarineController(MMSSystemContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View(); // This will look for Index.cshtml in Areas/MMS/Views/Marine
|
||||
}
|
||||
public IActionResult TarBallForm()
|
||||
{
|
||||
var marineTarballs = _context.MarineTarballs
|
||||
.Select(t => new
|
||||
{
|
||||
t.Id, //Include Id property
|
||||
Date = t.DateSample,
|
||||
Station = t.StationID
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return View();
|
||||
// For debugging
|
||||
Console.WriteLine("Fetched Data:");
|
||||
foreach (var item in marineTarballs)
|
||||
{
|
||||
Console.WriteLine($"Date: {item.Date}, Station: {item.Station}");
|
||||
}
|
||||
|
||||
return View(marineTarballs);
|
||||
}
|
||||
|
||||
public IActionResult GenerateReport()
|
||||
public IActionResult GenerateReport(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve specific data based on the id, if required
|
||||
var document = new TarBallPDF(); // Use id to customize the report if needed
|
||||
// Retrieve the specific record based on the id
|
||||
var tarballData = _context.MarineTarballs
|
||||
.Where(t => t.Id == id)
|
||||
.Select(t => new
|
||||
{
|
||||
t.StationID,
|
||||
t.DateSample
|
||||
})
|
||||
.FirstOrDefault();
|
||||
|
||||
if (tarballData == null)
|
||||
{
|
||||
return NotFound("The specified record was not found.");
|
||||
}
|
||||
|
||||
// Generate the PDF
|
||||
var document = new TarBallPDF(); // Customize the report if needed
|
||||
var pdf = document.GeneratePdf();
|
||||
var fileName = $"TarBallReport_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
|
||||
|
||||
// Construct the filename
|
||||
var formattedDate = tarballData.DateSample.ToString("ddMMyyyy");
|
||||
var fileName = $"TbReport_{tarballData.StationID}_{formattedDate}.pdf";
|
||||
|
||||
// Return the file
|
||||
return File(pdf, "application/pdf", fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -38,13 +81,34 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult ViewPDF()
|
||||
public IActionResult ViewPDF(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve specific data based on the id, if required
|
||||
var document = new TarBallPDF(); // Use id to customize the PDF if needed
|
||||
// Retrieve the specific record based on the id
|
||||
var tarballData = _context.MarineTarballs
|
||||
.Where(t => t.Id == id)
|
||||
.Select(t => new
|
||||
{
|
||||
t.StationID,
|
||||
t.DateSample
|
||||
})
|
||||
.FirstOrDefault();
|
||||
|
||||
if (tarballData == null)
|
||||
{
|
||||
return NotFound("The specified record was not found.");
|
||||
}
|
||||
|
||||
// Generate the PDF
|
||||
var document = new TarBallPDF(); // Customize the PDF if needed
|
||||
var pdf = document.GeneratePdf();
|
||||
|
||||
//For filename
|
||||
var formattedDate = tarballData.DateSample.ToString("ddMMyyyy");
|
||||
var fileName = $"TbReport_{tarballData.StationID}_{formattedDate}.pdf";
|
||||
|
||||
// Return the file
|
||||
return File(pdf, "application/pdf");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -53,5 +117,6 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while viewing the PDF. " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,6 @@
|
||||
color: #333; /* Dark grey for active state */
|
||||
font-weight: bold; /* Optional: Make it bold for emphasis */
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -76,7 +75,7 @@
|
||||
</select>
|
||||
|
||||
<div>
|
||||
<button @@click="clearFilters" class="btn btn-default" style="margin-top: 20px; margin-bottom: 25px;">Clear Filter</button>
|
||||
<button v-on:click="clearFilters" class="btn btn-default" style="margin-top: 20px; margin-bottom: 25px;">Clear Filter</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -85,34 +84,32 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No.</th>
|
||||
<th @@click="sortBy('date')">
|
||||
<th v-on:click="sortBy('date')">
|
||||
Date
|
||||
<span class="sort-arrow" :class="{ active: sortKey === 'date' && sortOrder === 'asc' }">▲</span>
|
||||
<span class="sort-arrow" :class="{ active: sortKey === 'date' && sortOrder === 'desc' }">▼</span>
|
||||
</th>
|
||||
<th @@click="sortBy('station')">
|
||||
<th v-on:click="sortBy('station')">
|
||||
Station
|
||||
<span class="sort-arrow" :class="{ active: sortKey === 'station' && sortOrder === 'asc' }">▲</span>
|
||||
<span class="sort-arrow" :class="{ active: sortKey === 'station' && sortOrder === 'desc' }">▼</span>
|
||||
</th>
|
||||
<th>Approval Status</th>
|
||||
<th>Status</th>
|
||||
<th>PDF</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr v-for="data in numberedData" :key="data.no">
|
||||
<td>{{ data.no }}</td>
|
||||
<td>{{ data.date }}</td>
|
||||
<tr v-for="(data, index) in numberedData" :key="data.id">
|
||||
<td>{{ index + 1 }}</td>
|
||||
<td>{{ new Date(data.date).toLocaleDateString('en-GB') }}</td>
|
||||
<td>{{ data.station }}</td>
|
||||
|
||||
<td>
|
||||
<button class="btn btn-success">Approve</button>
|
||||
<button class="btn btn-danger">Reject</button>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/MMS/Marine/ViewPDF" class="btn btn-primary" target="_blank">View PDF</a>
|
||||
<a href="/MMS/Marine/GenerateReport" class="btn btn-primary">Download PDF</a>
|
||||
<a :href="`/MMS/Marine/ViewPDF?id=${data.id}`" class="btn btn-primary" target="_blank">View PDF</a>
|
||||
<a :href="`/MMS/Marine/GenerateReport?id=${data.id}`" class="btn btn-primary">Download PDF</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@ -122,44 +119,31 @@
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@section Scripts{
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
selectedMonth: '',
|
||||
selectedYear: '',
|
||||
sortKey:'date',
|
||||
sortKey: 'date',
|
||||
sortOrder: 'desc',
|
||||
months: [
|
||||
'January', 'February', 'March', 'April', 'May',
|
||||
'June', 'July', 'August', 'September',
|
||||
'October', 'November', 'December'
|
||||
],
|
||||
mockData: [
|
||||
{ date: '2023-01-15', station: 'Station A' },
|
||||
{ date: '2024-02-20', station: 'Station B' },
|
||||
{ date: '2023-03-10', station: 'Station C' },
|
||||
{ date: '2025-04-05', station: 'Station A' },
|
||||
{ date: '2023-05-18', station: 'Station B' },
|
||||
{ date: '2024-06-11', station: 'Station C' },
|
||||
{ date: '2025-07-23', station: 'Station A' },
|
||||
{ date: '2023-08-09', station: 'Station B' },
|
||||
{ date: '2024-09-25', station: 'Station C' },
|
||||
{ date: '2025-10-14', station: 'Station A' }
|
||||
]
|
||||
dataFromServer: @Html.Raw(Json.Serialize(Model))
|
||||
},
|
||||
computed: {
|
||||
years() {
|
||||
const allYears = this.mockData.map(data => new Date(data.date).getFullYear());
|
||||
const allYears = this.dataFromServer.map(data => new Date(data.date).getFullYear());
|
||||
const minYear = Math.min(...allYears);
|
||||
const maxYear = Math.max(...allYears);
|
||||
return Array.from({ length: maxYear - minYear + 1 }, (_, i) => (minYear + i).toString());
|
||||
},
|
||||
// Filter data based on selected month and year
|
||||
filteredData() {
|
||||
return this.mockData.filter(data => {
|
||||
return this.dataFromServer.filter(data => {
|
||||
const date = new Date(data.date);
|
||||
const monthMatches = this.selectedMonth
|
||||
? date.toLocaleString('default', { month: 'long' }) === this.selectedMonth
|
||||
@ -170,23 +154,13 @@
|
||||
return monthMatches && yearMatches;
|
||||
});
|
||||
},
|
||||
|
||||
// Automatically sort data by the latest date
|
||||
numberedData() {
|
||||
return this.filteredData
|
||||
.slice()
|
||||
.sort((a, b) => {
|
||||
if (this.sortKey === 'date') {
|
||||
const dateA = new Date(a.date);
|
||||
const dateB = new Date(b.date);
|
||||
return this.sortOrder === 'asc' ? dateA - dateB : dateB - dateA;
|
||||
} else if (this.sortKey === 'station') {
|
||||
const stationA = a.station.toLowerCase();
|
||||
const stationB = b.station.toLowerCase();
|
||||
if (stationA < stationB) return this.sortOrder === 'asc' ? -1 : 1;
|
||||
if (stationA > stationB) return this.sortOrder === 'asc' ? 1 : -1;
|
||||
return 0;
|
||||
}
|
||||
const dateA = new Date(a.date);
|
||||
const dateB = new Date(b.date);
|
||||
return this.sortOrder === 'asc' ? dateA - dateB : dateB - dateA;
|
||||
})
|
||||
.map((data, index) => ({
|
||||
no: index + 1,
|
||||
@ -195,24 +169,19 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
//to clear filters
|
||||
clearFilters() {
|
||||
this.selectedMonth='';
|
||||
this.selectedYear='';
|
||||
this.selectedMonth = '';
|
||||
this.selectedYear = '';
|
||||
},
|
||||
sortBy(key) {
|
||||
if (this.sortKey === key) {
|
||||
// Toggle sort order if the same column is clicked
|
||||
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
// Set new sort key and default to ascending order
|
||||
this.sortKey = key;
|
||||
this.sortOrder = 'asc';
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
42
DBContext/MMSSystemContext.cs
Normal file
42
DBContext/MMSSystemContext.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PSTW_CentralSystem.Models; // Add this to use the MarineTarball class
|
||||
|
||||
namespace PSTW_CentralSystem.DBContext
|
||||
{
|
||||
public class MMSSystemContext : DbContext
|
||||
{
|
||||
public MMSSystemContext(DbContextOptions<MMSSystemContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
// DbSet for tbl_marine_tarball
|
||||
public DbSet<MarineTarball> MarineTarballs { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// Map MarineTarball to tbl_marine_tarball
|
||||
modelBuilder.Entity<MarineTarball>().ToTable("tbl_marine_tarball");
|
||||
|
||||
// Configure properties if needed
|
||||
modelBuilder.Entity<MarineTarball>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id); // Primary key
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.ReportID).HasColumnName("reportID").HasMaxLength(50);
|
||||
entity.Property(e => e.FirstSampler).HasColumnName("firstSampler").HasMaxLength(50);
|
||||
entity.Property(e => e.SecondSampler).HasColumnName("secondSampler").HasMaxLength(50);
|
||||
entity.Property(e => e.DateSample).HasColumnName("dateSample");
|
||||
entity.Property(e => e.TimeSample).HasColumnName("timeSample");
|
||||
entity.Property(e => e.StationID).HasColumnName("stationID").HasMaxLength(20);
|
||||
entity.Property(e => e.ClassifyID).HasColumnName("classifyID").HasMaxLength(20);
|
||||
entity.Property(e => e.Latitude).HasColumnName("latitude");
|
||||
entity.Property(e => e.Longitude).HasColumnName("longitude");
|
||||
entity.Property(e => e.GetLatitude).HasColumnName("getLatitude");
|
||||
entity.Property(e => e.GetLongitude).HasColumnName("getLongitude");
|
||||
entity.Property(e => e.Timestamp).HasColumnName("timestamp");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Models/MarineTarball.cs
Normal file
21
Models/MarineTarball.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace PSTW_CentralSystem.Models
|
||||
{
|
||||
public class MarineTarball
|
||||
{
|
||||
public int Id { get; set; } // Maps to 'id'
|
||||
public string ReportID { get; set; } // Maps to 'reportID'
|
||||
public string FirstSampler { get; set; } // Maps to 'firstSampler'
|
||||
public string SecondSampler { get; set; } // Maps to 'secondSampler'
|
||||
public DateTime DateSample { get; set; } // Maps to 'dateSample'
|
||||
public TimeSpan TimeSample { get; set; } // Maps to 'timeSample'
|
||||
public string StationID { get; set; } // Maps to 'stationID'
|
||||
public string ClassifyID { get; set; } // Maps to 'classifyID'
|
||||
public double Latitude { get; set; } // Maps to 'latitude'
|
||||
public double Longitude { get; set; } // Maps to 'longitude'
|
||||
public double GetLatitude { get; set; } // Maps to 'getLatitude'
|
||||
public double GetLongitude { get; set; } // Maps to 'getLongitude'
|
||||
public DateTime Timestamp { get; set; } // Maps to 'timestamp'
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
||||
<PackageReference Include="MySql.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="PDFsharp" Version="6.1.1" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||
|
||||
12
Program.cs
12
Program.cs
@ -50,6 +50,12 @@ internal class Program
|
||||
mysqlOptions => mysqlOptions.CommandTimeout(120)
|
||||
);
|
||||
});
|
||||
|
||||
builder.Services.AddDbContext<MMSSystemContext>(options =>
|
||||
options.UseMySql(builder.Configuration.GetConnectionString("MMSDatabase"),
|
||||
new MySqlServerVersion(new Version(8, 0, 0))));
|
||||
|
||||
|
||||
//builder.Services.AddDbContext<InventoryDBContext>(options =>
|
||||
//{
|
||||
// options.UseMySql(inventoryConnectionString, new MySqlServerVersion(new Version(8, 0, 39)),
|
||||
@ -95,6 +101,12 @@ internal class Program
|
||||
app.MapControllerRoute(
|
||||
name: "root",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
app.MapControllerRoute(
|
||||
name: "areas",
|
||||
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
@ -3,9 +3,10 @@
|
||||
//"DefaultConnection": "Server=localhost;uid=root;Password='';Database=web_interface;"
|
||||
//"DefaultConnection": "server=175.136.244.102;user id=root;password=tw_mysql_root;port=3306;database=web_interface"
|
||||
//"CentralConnnection": "Server=192.168.12.12;Port=3306;uid=installer;password='pstw_mysql_installer';database=pstw_cs;", //DB_dev Local connection
|
||||
"CentralConnnection": "Server=219.92.7.60;Port=3307;uid=installer;password='pstw_mysql_installer';database=pstw_cs;" //DB_dev Public connection
|
||||
"CentralConnnection": "Server=219.92.7.60;Port=3307;uid=installer;password='pstw_mysql_installer';database=pstw_cs;", //DB_dev Public connection
|
||||
//"InventoryConnection": "Server=219.92.7.60;Port=3307;uid=installer;password='pstw_mysql_installer';database=pstw_cs_inventory;" //DB_dev connection
|
||||
//"DefaultConnection": "Server=219.92.7.60;Port=3307;uid=intern;password='intern_mysql_acct';database=web_interface;"//DB_dev connection
|
||||
"MMSDatabase": "Server=192.168.12.42;Port=3306;Uid=mmsuser;password=mms@pstw_mysql_root;database=db_mms;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user