Browse Source

Finished Transparency View

tags/2.0.3
Teknikode 5 years ago
parent
commit
0cc40ad6ae

+ 88
- 0
Teknik/Areas/Transparency/Controllers/TransparencyController.cs View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Teknik.Areas.Transparency.Models;
using Teknik.Areas.Transparency.ViewModels;
using Teknik.Controllers;
using Teknik.Models;

namespace Teknik.Areas.Transparency.Controllers
{
public class TransparencyController : DefaultController
{
private TeknikEntities db = new TeknikEntities();

[AllowAnonymous]
public ActionResult Index()
{
TransparencyViewModel model = new TransparencyViewModel();

Upload.Models.Upload upload = db.Uploads.OrderByDescending(u => u.UploadId).FirstOrDefault();
model.UploadCount = (upload != null) ? upload.UploadId : 0;
model.UploadSize = (upload != null) ? db.Uploads.Sum(u => u.ContentLength) : 0;

Paste.Models.Paste paste = db.Pastes.OrderByDescending(p => p.PasteId).FirstOrDefault();
model.PasteCount = (paste != null) ? paste.PasteId : 0;

Profile.Models.User user = db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
model.UserCount = (user != null) ? user.UserId : 0;

model.TotalNet = new Dictionary<string, double>();

var billSums = db.Transactions.OfType<Bill>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
model.TotalBills = new Dictionary<string, double>();
foreach (var sum in billSums)
{
model.TotalBills.Add(sum.currency, sum.total);
if (model.TotalNet.ContainsKey(sum.currency))
{
model.TotalNet[sum.currency] += sum.total;
}
else
{
model.TotalNet.Add(sum.currency, sum.total);
}
}

var oneSums = db.Transactions.OfType<OneTime>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
model.TotalOneTimes = new Dictionary<string, double>();
foreach (var sum in oneSums)
{
model.TotalOneTimes.Add(sum.currency, sum.total);
if (model.TotalNet.ContainsKey(sum.currency))
{
model.TotalNet[sum.currency] += sum.total;
}
else
{
model.TotalNet.Add(sum.currency, sum.total);
}
}

var donationSums = db.Transactions.OfType<Donation>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
model.TotalDonations = new Dictionary<string, double>();
foreach (var sum in donationSums)
{
model.TotalDonations.Add(sum.currency, sum.total);
if (model.TotalNet.ContainsKey(sum.currency))
{
model.TotalNet[sum.currency] += sum.total;
}
else
{
model.TotalNet.Add(sum.currency, sum.total);
}
}

model.Bills = db.Transactions.OfType<Bill>().OrderByDescending(b => b.DateSent).ToList();
model.OneTimes = db.Transactions.OfType<OneTime>().OrderByDescending(b => b.DateSent).ToList();
model.Donations = db.Transactions.OfType<Donation>().OrderByDescending(b => b.DateSent).ToList();

model.Takedowns = db.Takedowns.OrderByDescending(b => b.DateRequested).ToList();

return View(model);
}
}
}

Teknik/Areas/Transparency/Models/Single.cs → Teknik/Areas/Transparency/Models/OneTime.cs View File

@@ -6,7 +6,8 @@ using System.Threading.Tasks;

namespace Teknik.Areas.Transparency.Models
{
public class Single : Transaction
public class OneTime : Transaction
{
public string Recipient { get; set; }
}
}

+ 1
- 1
Teknik/Areas/Transparency/Models/Transaction.cs View File

@@ -10,7 +10,7 @@ namespace Teknik.Areas.Transparency.Models
{
public int TransactionId { get; set; }

public int Amount { get; set; }
public double Amount { get; set; }

public string Currency { get; set; }


+ 10
- 7
Teknik/Areas/Transparency/TransparencyAreaRegistration.cs View File

@@ -1,4 +1,5 @@
using System.Web.Mvc;
using System.Collections.Generic;
using System.Web.Mvc;

namespace Teknik.Areas.Transparency
{
@@ -12,13 +13,15 @@ namespace Teknik.Areas.Transparency
}
}

public override void RegisterArea(AreaRegistrationContext context)
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Transparency_default",
"Transparency/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
context.MapSubdomainRoute(
"Transparency.Index",
new List<string>() { "dev", "transparency" }, // Subdomains
"",
new { controller = "Transparency", action = "Index" },
new[] { typeof(Controllers.TransparencyController).Namespace }
);
}
}
}

+ 19
- 0
Teknik/Areas/Transparency/ViewModels/TransparencyViewModel.cs View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teknik.Areas.Transparency.Models;
using Teknik.ViewModels;

namespace Teknik.Areas.Transparency.ViewModels
@@ -11,8 +12,26 @@ namespace Teknik.Areas.Transparency.ViewModels
{
public int UploadCount { get; set; }

public int UploadSize { get; set; }

public int PasteCount { get; set; }

public int UserCount { get; set; }

public Dictionary<string, double> TotalBills { get; set; }

public Dictionary<string, double> TotalOneTimes { get; set; }

public Dictionary<string, double> TotalDonations { get; set; }

public Dictionary<string, double> TotalNet { get; set; }

public List<Bill> Bills { get; set; }

public List<OneTime> OneTimes { get; set; }

public List<Donation> Donations { get; set; }

public List<Takedown> Takedowns { get; set; }
}
}

+ 185
- 296
Teknik/Areas/Transparency/Views/Transparency/Index.cshtml View File

@@ -1,5 +1,8 @@
@model Teknik.Areas.Transparency.ViewModels.TransparencyViewModel

@using Teknik.Helpers
@using Teknik.Areas.Transparency.Models

<div class="container">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
@@ -20,22 +23,18 @@
<div class="row">
<div class="col-sm-6">
<h3>Uploads</h3>
<p>Number of Uploads: <?php echo count($upload_list); ?></p>
<p>Total Size: <?php echo bytesToSize($total_size['TotalSize']); ?></p>
<p>Number of Uploads: @Model.UploadCount</p>
<p>Total Size: @Utility.GetBytesReadable(Model.UploadSize)</p>
</div>
<div class="col-sm-6">
<h3>Pastes</h3>
<p>Number of Pastes: <?php echo $paste_list[0]['pid']; ?></p>
<p>Number of Pastes: @Model.PasteCount</p>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<h3>Users</h3>
<p>Number of Users: <?php echo count($user_list); ?></p>
</div>
<div class="col-sm-6">
<h3>Usage</h3>
<p>No Usage Reports</p>
<p>Number of Users: @Model.UserCount</p>
</div>
</div>
<br />
@@ -45,318 +44,208 @@
<div class="row">
<div class="col-sm-3 text-center">
<h4>Donations</h4>
<?php
foreach ($total_donation_list as $total)
@foreach (var val in Model.TotalDonations)
{
echo "<p>
".round($total['TotalAmount'], 2)." ".$total['currency'];
}
?>
<p>@Math.Round(val.Value, 2) @val.Key</p>
}
</div>
<div class="col-sm-3 text-center">
<h4>Bills</h4>
<?php
foreach ($total_bill_list as $total)
@foreach (var val in Model.TotalBills)
{
echo "<p>
".round($total['TotalAmount'], 2)." ".$total['currency'];
}
?>
<p>@Math.Round(val.Value, 2) @val.Key</p>
}
</div>
<div class="col-sm-3 text-center">
<h4>One-Time Payments</h4>
<?php
foreach ($total_one_time_list as $total)
@foreach (var val in Model.TotalOneTimes)
{
echo "<p>
".round($total['TotalAmount'], 2)." ".$total['currency'];
}
?>
<p>@Math.Round(val.Value, 2) @val.Key</p>
}
</div>
<div class="col-sm-3 text-center">
<h4>Net Profit</h4>
<?php
foreach ($total_net_list as $total)
@foreach (var val in Model.TotalNet)
{
echo "<p>
".round($total['TotalAmount'], 2)." ".$total['currency'];
}
?>
<p>@Math.Round(val.Value, 2) @val.Key</p>
}
</div>
</div>
<?php
if ($transactions_bills)
@if (Model.Bills != null && Model.Bills.Any())
{
?>
<h3>Bills</h3>
<?php
$current_month = null;
$first_event = true;
foreach ($transaction_bill_list as $transaction)
{
$transaction_date = (isset($transaction['date_posted'])) ? $transaction['date_posted'] : "";
$transaction_reason = (isset($transaction['reason'])) ? $transaction['reason'] : "";
$transaction_amount = (isset($transaction['amount'])) ? $transaction['amount'] : "";
$transaction_currency = (isset($transaction['currency'])) ? $transaction['currency'] : "";

$new_month_tag = false;
if ($current_month != date("F",strtotime($transaction_date)) || $current_year != date("Y",strtotime($transaction_date)))
{
$new_month_tag = true;
}
$current_month = date("F",strtotime($transaction_date));
$current_year = date("Y",strtotime($transaction_date));
?>
<?php if (!$first_event && $new_month_tag) { ?>
</div>
<?php } ?>
<?php if ($new_month_tag) { ?>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#bills-<?php echo $current_month.'-'.$current_year; ?>"><?php echo $current_month.', '.$current_year; ?></button>
</div>
</div>
<br />
<div id="bills-<?php echo $current_month.'-'.$current_year; ?>" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Date</strong></h4>
<h3>Bills</h3>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#bills-section">View Bills</button>
</div>
</div>
<div class="col-sm-2">
<h4><strong>Amount</strong></h4>
<br />
<div id="bills-section" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Date</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Amount</strong></h4>
</div>
<div class="col-sm-8">
<h4><strong>Description</strong></h4>
</div>
</div>
@foreach (Bill bill in Model.Bills)
{
<div class="row">
<div class="col-sm-2">
@bill.DateSent.ToString("MMMM dd, yyyy")
</div>
<div class="col-sm-2">
@bill.Amount <var>@bill.Currency</var>
</div>
<div class="col-sm-8">
@bill.Reason
</div>
</div>
}
</div>
<div class="col-sm-8">
<h4><strong>Reason for Transaction</strong></h4>
}
@if (Model.OneTimes != null && Model.OneTimes.Any())
{
<h3>One Time Payments</h3>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#oneTime-section">View Payments</button>
</div>
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-sm-2">
<?php echo $transaction_date; ?>
<br />
<div id="oneTime-section" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Date</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Amount</strong></h4>
</div>
<div class="col-sm-8">
<h4><strong>Reason for Payment</strong></h4>
</div>
</div>
@foreach (OneTime oneTime in Model.OneTimes)
{
<div class="row">
<div class="col-sm-2">
@oneTime.DateSent.ToString("MMMM dd, yyyy")
</div>
<div class="col-sm-2">
@oneTime.Amount <var>@oneTime.Currency</var>
</div>
<div class="col-sm-8">
@oneTime.Reason
</div>
</div>
}
</div>
<div class="col-sm-2">
<?php echo $transaction_amount." <var>".$transaction_currency."</var>"; ?>
}
@if (Model.Donations != null && Model.Donations.Any())
{
<h3>Donations</h3>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#donations-section">View Donations</button>
</div>
</div>
<div class="col-sm-8">
<?php echo $transaction_reason; ?>
<br />
<div id="donations-section" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Date</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Amount</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Donor</strong></h4>
</div>
<div class="col-sm-6">
<h4><strong>Reason for Donation</strong></h4>
</div>
</div>
@foreach (Donation donation in Model.Donations)
{
<div class="row">
<div class="col-sm-2">
@donation.DateSent.ToString("MMMM dd, yyyy")
</div>
<div class="col-sm-2">
@donation.Amount <var>@donation.Currency</var>
</div>
<div class="col-sm-2">
@donation.Sender
</div>
<div class="col-sm-6">
@donation.Reason
</div>
</div>
}
</div>
</div>
<br />
<?php
$first_event = false;
}
?>
</div>
<?php
}

if ($transactions_one_time)
{
?>
<h3>One-Time Payments</h3>
<?php
$current_month = null;
$first_event = true;
foreach ($transaction_one_time_list as $transaction)
{
$transaction_date = (isset($transaction['date_posted'])) ? $transaction['date_posted'] : "";
$transaction_reason = (isset($transaction['reason'])) ? $transaction['reason'] : "";
$transaction_amount = (isset($transaction['amount'])) ? $transaction['amount'] : "";
$transaction_currency = (isset($transaction['currency'])) ? $transaction['currency'] : "";

$new_month_tag = false;
if ($current_month != date("F",strtotime($transaction_date)) || $current_year != date("Y",strtotime($transaction_date)))
{
$new_month_tag = true;
}
$current_month = date("F",strtotime($transaction_date));
$current_year = date("Y",strtotime($transaction_date));
?>
<?php if (!$first_event && $new_month_tag) { ?>
</div>
<?php } ?>
<?php if ($new_month_tag) { ?>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#One-Time-<?php echo $current_month.'-'.$current_year; ?>"><?php echo $current_month.' - '.$current_year; ?></button>
</div>
</div>
<br />
<div id="One-Time-<?php echo $current_month.'-'.$current_year; ?>" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Date</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Amount</strong></h4>
</div>
<div class="col-sm-8">
<h4><strong>Reason for Transaction</strong></h4>
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-sm-2">
<?php echo $transaction_date; ?>
</div>
<div class="col-sm-2">
<?php echo $transaction_amount." <var>".$transaction_currency."</var>"; ?>
</div>
<div class="col-sm-8">
<?php echo $transaction_reason; ?>
</div>
</div>
<br />
<?php
$first_event = false;
}
?>
</div>
<?php
}

if ($transactions_donations)
{
?>
<h3>Donations</h3>
<?php
$current_month = null;
$first_event = true;
foreach ($transaction_donation_list as $transaction)
{
$transaction_date = (isset($transaction['date_posted'])) ? $transaction['date_posted'] : "";
$transaction_reason = (isset($transaction['reason'])) ? $transaction['reason'] : "";
$transaction_amount = (isset($transaction['amount'])) ? $transaction['amount'] : "";
$transaction_currency = (isset($transaction['currency'])) ? $transaction['currency'] : "";

$new_month_tag = false;
if ($current_month != date("F",strtotime($transaction_date)) || $current_year != date("Y",strtotime($transaction_date)))
{
$new_month_tag = true;
}
$current_month = date("F",strtotime($transaction_date));
$current_year = date("Y",strtotime($transaction_date));
?>
<?php if (!$first_event && $new_month_tag) { ?>
</div>
<?php } ?>
<?php if ($new_month_tag) { ?>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#donations-<?php echo $current_month.'-'.$current_year; ?>"><?php echo $current_month.' - '.$current_year; ?></button>
</div>
</div>
<br />
<div id="donations-<?php echo $current_month.'-'.$current_year; ?>" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Date</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Amount</strong></h4>
</div>
<div class="col-sm-8">
<h4><strong>Reason for Transaction</strong></h4>
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-sm-2">
<?php echo $transaction_date; ?>
</div>
<div class="col-sm-2">
<?php echo $transaction_amount." <var>".$transaction_currency."</var>"; ?>
</div>
<div class="col-sm-8">
<?php echo $transaction_reason; ?>
</div>
</div>
<br />
<?php
$first_event = false;
}
?>
</div>
<?php
}
?>
<br />
<h2 class="text-center"><b>Takedowns</b></h2>
<hr>
<?php
if ($takedown_list)
{
$current_month = date("F",time())+1;
$first_event = true;
foreach ($takedown_list as $takedown)
<br />
<h2 class="text-center"><b>Takedowns</b></h2>
<hr>
@if (Model.Takedowns != null && Model.Takedowns.Any())
{
$takedown_date = (isset($takedown['date_requested'])) ? $takedown['date_requested'] : "";
$takedown_requester = (isset($takedown['requester'])) ? $takedown['requester'] : "";
$takedown_reason = (isset($takedown['reason'])) ? $takedown['reason'] : "";
$takedown_action = (isset($takedown['action'])) ? $takedown['action'] : "";

$new_month_tag = false;
if ($current_month != date("F",strtotime($takedown_date)))
{
$new_month_tag = true;
}
$current_month = date("F",strtotime($takedown_date));
$current_year = date("Y",strtotime($takedown_date));
?>
<?php if (!$first_event && $new_month_tag) { ?>
</div>
<?php } ?>
<?php if ($new_month_tag) { ?>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#donations-<?php echo $current_month.'-'.$current_year; ?>"><?php echo $current_month.' - '.$current_year; ?></button>
</div>
</div>
<br />
<div id="donations-<?php echo $current_month.'-'.$current_year; ?>" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Date</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Requester</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Action Taken</strong></h4>
</div>
<div class="col-sm-6">
<h4><strong>Takedown Reason</strong></h4>
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-sm-2">
<p><?php echo $takedown_date; ?></p>
</div>
<div class="col-sm-2">
<p><?php echo $takedown_requester; ?></p>
</div>
<div class="col-sm-2">
<p><?php echo $takedown_action; ?></p>
</div>
<div class="col-sm-6">
<?php echo $takedown_reason; ?>
<h3>Takedowns</h3>
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#takedowns-section">View Takedowns</button>
</div>
</div>
<br />
<div id="takedowns-section" class="collapse">
<div class="row">
<div class="col-sm-2">
<h4><strong>Requester</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Contact</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Reason</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Action Taken</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Date Requested</strong></h4>
</div>
<div class="col-sm-2">
<h4><strong>Date Of Action</strong></h4>
</div>
</div>
@foreach (Takedown takedown in Model.Takedowns)
{
<div class="row">
<div class="col-sm-2">
@takedown.Requester
</div>
<div class="col-sm-2">
@takedown.RequesterContact
</div>
<div class="col-sm-2">
@takedown.Reason
</div>
<div class="col-sm-2">
@takedown.ActionTaken
</div>
<div class="col-sm-2">
@takedown.DateRequested.ToString("MMMM dd, YYYY")
</div>
<div class="col-sm-2">
@takedown.DateActionTaken.ToString("MMMM dd, YYYY")
</div>
</div>
}
</div>
}
</div>
</div>
<br />
<?php
$first_event = false;
}
?>
</div>
<?php
}
else
{
echo "<h3 class='text-center'>No Takedowns Requested</h3>";
}
?>
<br />
</div>
</div>
</div>

+ 2
- 0
Teknik/Models/TeknikEntities.cs View File

@@ -38,6 +38,7 @@ namespace Teknik.Models
public DbSet<PodcastComment> PodcastComments { get; set; }
// Transparency
public DbSet<Transaction> Transactions { get; set; }
public DbSet<Takedown> Takedowns { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
@@ -86,6 +87,7 @@ namespace Teknik.Models
modelBuilder.Entity<PodcastComment>().ToTable("PodcastComments");
// Transparency
modelBuilder.Entity<Transaction>().ToTable("Transactions");
modelBuilder.Entity<Takedown>().ToTable("Takedowns");

base.OnModelCreating(modelBuilder);
}

+ 3
- 1
Teknik/Teknik.csproj View File

@@ -204,7 +204,9 @@
<Compile Include="Areas\Transparency\Controllers\TransparencyController.cs" />
<Compile Include="Areas\Transparency\Models\Bill.cs" />
<Compile Include="Areas\Transparency\Models\Donation.cs" />
<Compile Include="Areas\Transparency\Models\Single.cs" />
<Compile Include="Areas\Transparency\Models\MonthYearGroup.cs" />
<Compile Include="Areas\Transparency\Models\OneTime.cs" />
<Compile Include="Areas\Transparency\Models\Takedown.cs" />
<Compile Include="Areas\Transparency\Models\Transaction.cs" />
<Compile Include="Areas\Transparency\TransparencyAreaRegistration.cs" />
<Compile Include="Areas\Transparency\ViewModels\TransparencyViewModel.cs" />

Loading…
Cancel
Save