Skip to content

Commit

Permalink
Merge pull request #98 from griidc/release/5.8.0
Browse files Browse the repository at this point in the history
Release/5.8.0
  • Loading branch information
praneethpr authored Nov 27, 2018
2 parents 51bd108 + 1991f05 commit 3664eb3
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 53 deletions.
36 changes: 36 additions & 0 deletions app/DoctrineMigrations/Version20181107205545.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Pelagos\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20181107205545 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('ALTER TABLE dataset ADD accepted_date TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL');
$this->addSql('ALTER TABLE dataset_audit ADD accepted_date TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('ALTER TABLE dataset DROP accepted_date');
$this->addSql('ALTER TABLE dataset_audit DROP accepted_date');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

namespace Pelagos\Bundle\AppBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Pelagos\Entity\Dataset;

/**
* Back fill script for accepted date for Dataset entity.
*
* @see ContainerAwareCommand
*/
class BackFillAcceptedDateDatasetCommand extends ContainerAwareCommand
{
/**
* Configures the current command.
*
* @return void
*/
protected function configure()
{
$this
->setName('dataset:backfill-accepted-date')
->setDescription('Backfill Dataset accepted date for approved datasets.');
}

/**
* Executes the current command.
*
* @param InputInterface $input An InputInterface instance.
* @param OutputInterface $output An OutputInterface instance.
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');

$datasets = $entityManager->getRepository(Dataset::class)->findBy(array('datasetStatus' => Dataset::DATASET_STATUS_ACCEPTED));
$count = 0;
$acceptedDateTimeStamp = new \DateTime();

foreach ($datasets as $dataset) {

$queryString = 'select id, rev, dataset_id, dataset_status, modification_time_stamp
from dataset_submission_audit where dataset_id = :datasetId order by rev desc, id desc';
$params = [
'datasetId' => $dataset->getId(),
];
$params['datasetId'] = $dataset->getId();
$stmt = $entityManager->getConnection()->prepare($queryString);
$stmt->execute($params);
$auditRevisionFinder = $stmt->fetchAll();

$numberOfRevisions = count($auditRevisionFinder);
if ($numberOfRevisions > 1) {
for ($i = ($numberOfRevisions - 1); $i > 0; $i --) {
// The revisions are ordered by latest first.
$oldRevision = $auditRevisionFinder[$i];
$newRevision = $auditRevisionFinder[($i - 1)];

$articleDiff = $this->diff($oldRevision, $newRevision);

if ($i === ($numberOfRevisions - 1) and $articleDiff['dataset_status']['same'] === Dataset::DATASET_STATUS_ACCEPTED) {
$acceptedDateTimeStamp = $articleDiff['modification_time_stamp']['old'];
}

if ($articleDiff['dataset_status']['new'] === Dataset::DATASET_STATUS_ACCEPTED) {
if (!empty($articleDiff['modification_time_stamp']['new'])) {
$acceptedDateTimeStamp = $articleDiff['modification_time_stamp']['new'];
} else {
$acceptedDateTimeStamp = $articleDiff['modification_time_stamp']['same'];
}
}
}
} else {
$acceptedDateTimeStamp = $dataset->getModificationTimeStamp();
}

$acceptedDateTimeStamp = new \DateTime($acceptedDateTimeStamp);

if ($acceptedDateTimeStamp instanceof \DateTime) {

$entityManager->clear();
$newDataset = $entityManager->getRepository(Dataset::class)->findOneBy(array('id' => $dataset->getId()));

$newDataset->setAcceptedDate($acceptedDateTimeStamp);
$output->writeln('Accepted date back-filled for dataset: ' . $dataset->getId());
$entityManager->persist($newDataset);
$entityManager->flush();
$count++;
} else {
$output->writeln('Modification Time stamp not an instance of DateTime for Dataset Id: ' . $dataset->getId());
}
$acceptedDateTimeStamp = null;
}

$output->writeln('Total number of datasets which got back-filled: ' . $count);
}

/**
* Creates a diff between 2 arrays.
*
* @param array $oldData Array which contains the old data.
* @param array $newData Array which contains the new data.
*
* @return array
*/
public function diff($oldData, $newData)
{
$diff = array();

$keys = array_keys($oldData + $newData);
foreach ($keys as $field) {
$old = array_key_exists($field, $oldData) ? $oldData[$field] : null;
$new = array_key_exists($field, $newData) ? $newData[$field] : null;

if ($old == $new) {
$row = array('old' => '', 'new' => '', 'same' => $old);
} else {
$row = array('old' => $old, 'new' => $new, 'same' => '');
}

$diff[$field] = $row;
}

return $diff;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function getVersions(Request $request)
$data['modificationtimestamp'] = $submission->getModificationTimeStamp()->format('c');
$submissions[] = $data;
}

$dataset = $datasetSubmissionHistory->first()->getDataset();
$submissions['datasetstatus'] = Dataset::DATASET_STATUSES[$dataset->getDatasetStatus()];
$submissions['udi'] = $dataset->getUdi();

return new JsonResponse(
$submissions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ function resizeLeftRight() {
$("#left").height(lh);
$("#right").height(rh);
}

//base 10
function formatBytes(bytes,decimals) {
if(bytes == 0) return "0 Bytes";
var k = 1024,
var k = 1000,
dm = decimals <= 0 ? 0 : decimals || 2,
sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
i = Math.floor(Math.log(bytes) / Math.log(k));
Expand Down
42 changes: 24 additions & 18 deletions src/Pelagos/Bundle/AppBundle/Resources/public/js/sidebyside.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var $ = jQuery.noConflict();
$(document).ready(function()
{
"use strict";

$("#get-versions-button").click(function (){
var udi = $("input[name=udi]").val().trim();
jQuery.ajax({
Expand All @@ -15,22 +15,30 @@ $(document).ready(function()
.success(function(data) {
var select = $("select.version-select");
select.find("option").remove();

$.each(data, function(index, item) {
var option = new Option(item.sequence, item.sequence);
$(option).data("udi", item.udi);
$(option).data("modificationtimestamp", item.modificationtimestamp);
$(option).data("status", item.status);
$(option).data("version", item.version);
$(option).data("modifier", item.modifier);
select.append(option);
if (typeof item === "object") {
var option = new Option(item.sequence, item.sequence);
$(option).data("udi", item.udi);
$(option).data("modificationtimestamp", item.modificationtimestamp);
$(option).data("status", item.status);
$(option).data("version", item.version);
$(option).data("modifier", item.modifier);
select.append(option);
}
});

$(".right-version").find("select option:selected")
.prop("selected", false)
.next()
.prop("selected", "selected");
select.change();

// Count the number of options, but divide by 2,
// because there are two select boxes (with options).
$("#numversions").text(select.find("option").size() / 2);
$("#datasetstatus").text(data.datasetstatus);
$(".udi-title").text(data.udi);
})
.error(function() {
var n = new noty({
Expand All @@ -46,14 +54,13 @@ $(document).ready(function()
$("input[name=udi]").val("");
});
});

$(".left-version").find("select").change(function() {
var version = $(this).find("option:selected").data("version");
var udi = $(this).find("option:selected").data("udi");

$("#left").html($(".spinner div").html());
$(".udi-title").text(udi);


$(this).parents("div.left-version")
.find(".submission-status")
.text($(this).find("option:selected").data("status"));
Expand All @@ -69,14 +76,13 @@ $(document).ready(function()
$(".filetabs", this).tabs();
});
});

$(".right-version").find("select").change(function() {
var version = $(this).find("option:selected").data("version");
var udi = $(this).find("option:selected").data("udi");

$("#right").html($(".spinner div").html());
$(".udi-title").text(udi);


$(this).parents("div.right-version")
.find(".submission-status")
.text($(this).find("option:selected").data("status"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
<div class="cleair">
<fieldset>
<p>
<strong>NOTE:</strong> <span style="color:grey">You must have an approved Dataset Information Form (DIF) to fill out and submit a Dataset Submission Form. The red asterisk (<span class="emRequired"/>) is used to indicate required fields. If you need assistance while completing this form, please contact <a href=mailto:griidc@gomri.org>[email protected]</a>.</span>
</p>
<strong>NOTE:
By submitting content to GRIIDC you warrant that you have sufficient rights to make this content available under a <a href="https://creativecommons.org/publicdomain/zero/1.0/" target="_blank">CC0 license</a>.
</strong>
</fieldset>

<p> <!-- Registry Identifier -->
<fieldset>
<p>
Please enter the Unique Dataset Identifier (UDI) that GRIIDC assigned to your dataset and select "Load Dataset" to load the most recent information for your dataset.
</p>
<form id="regidform">
<label for="regid"><b>Unique Dataset Identifier (UDI): </b></label>
<input minlength="16" type="text" id="regid" name="regid" size="60" value="{{datasetSubmission.getDatasetSubmissionId|default}}">
<button disabled
onclick="window.location.href='{{ path('pelagos_app_ui_datasetsubmission_default') }}?regid=' +
document.getElementById('regid').value.trim();"
name="regbutton" id="regbutton"
type="button">Load Dataset</button>
<label class="error" for="regid"></label>
</form>
</fieldset>
<fieldset>
<p>
Please enter the Unique Dataset Identifier (UDI) that GRIIDC assigned to your dataset and select "Load Dataset" to load the most recent information for your dataset. You must have an approved Dataset Information Form (DIF) to fill out and submit a Dataset Submission Form.
</p>
<fieldset>
<b>Approved Dataset Information Forms</b>
{% include "PelagosAppBundle:DatasetSubmission:datasets-approved-difs.html.twig" %}
</fieldset>
<form id="regidform">
<label for="regid"><b>Unique Dataset Identifier (UDI): </b></label>
<input minlength="16" type="text" id="regid" name="regid" size="60" value="{{datasetSubmission.getDatasetSubmissionId|default}}">
<button disabled
onclick="window.location.href='{{ path('pelagos_app_ui_datasetsubmission_default') }}?regid=' +
document.getElementById('regid').value.trim();"
name="regbutton" id="regbutton"
type="button">Load Dataset</button>
<label class="error" for="regid"></label>
</form>
<br>
<b>Approved Dataset Information Forms</b>
{% include "PelagosAppBundle:DatasetSubmission:datasets-approved-difs.html.twig" %}
</fieldset>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,24 @@
<h1>UDI: <span class="udi-title"></span></h1>
<table class="side-table">
<tr>
<td colspan="8" width="100%">
<label>UDI:</label>
<input name="udi" size="100">
<button id="get-versions-button" type="button">Get UDI</button>
<td width="50%">
<span style="white-space:nowrap;">
<label>UDI:</label>
<input name="udi" size="100">
<button id="get-versions-button" type="button">Get UDI</button>
</span>
</td>
<tr>
<td width="25%">
<label>Number of Versions:</label>
<div id="numversions">
</td>
<td width="25%">
<label>Dataset State:</label>
<div id="datasetstatus">
</td>
</tr>
</table>
<table class="side-table">
<tr>
<td>
<div class="left-version">
Expand All @@ -96,8 +108,8 @@
</td>
</tr>
<tr>
<td>
<label>Status:</label>
<td>
<label>Submission Status:</label>
<div class="submission-status">STATUS</div>
</td>
<td>
Expand Down Expand Up @@ -125,7 +137,7 @@
</tr>
<tr>
<td>
<label>Status:</label>
<label>Submission Status:</label>
<div class="submission-status">STATUS</div>
</td>
<td>
Expand Down
4 changes: 2 additions & 2 deletions src/Pelagos/Bundle/AppBundle/Twig/Extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function transformXml($xml, $xsl)
}

/**
* Format bytes as a human-readable string.
* Format bytes as a human-readable string (base 10).
*
* @param integer $bytes The bytes to format.
* @param integer $precision The the precision to use (default: 0).
Expand All @@ -305,7 +305,7 @@ public static function formatBytes($bytes, $precision = 0)
{
$units = array('B','KB','MB','GB','TB');
for ($e = (count($units) - 1); $e > 0; $e--) {
$one = pow(1024, $e);
$one = pow(1000, $e);
if ($bytes >= $one) {
return round(($bytes / $one), $precision) . ' ' . $units[$e];
}
Expand Down
Loading

0 comments on commit 3664eb3

Please sign in to comment.