Skip to content

Commit

Permalink
Merge pull request #1231 from sillsdev/staging
Browse files Browse the repository at this point in the history
Release 1.10.0
  • Loading branch information
rmunn authored Oct 28, 2021
2 parents aa0751c + 47bb3ac commit 0fd368c
Show file tree
Hide file tree
Showing 33 changed files with 1,004 additions and 200 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ src/assets/*
!src/assets/.gitkeep
src/cache/*
!src/cache/.gitkeep
!/src/releasenotes
test/php/\.phpunit\.result\.cache
node_modules
.DS_Store
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ Production deployments can be run with `VERSION=<some-docker-tag-or-semver> make

Current workflow:
1. merge from `staging` into `master`
1. tag the desired commit on `master` with a `v#.#.#` format and push the tag
1. "Draft a new release" on https://github.com/sillsdev/web-languageforge/releases with a `v#.#.#` tag format
1. "Publish" the new release
1. this will kick off the GHA (`.github/workflows/build-and-deploy-images.yml`) to build and publish the necessary images to Docker Hub (https://hub.docker.com/r/sillsdev/web-languageforge/tags)
1. then the deployment scripts can be run either manually or via the TeamCity deploy job

Expand Down
311 changes: 255 additions & 56 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"core-js": "^2.4.1",
"crc-32": "^1.2.0",
"date-fns": "^2.23.0",
"deep-diff": "^1.0.2",
"font-awesome": "^4.7.0",
"intl-tel-input": "9.2.7",
"jquery": "^3.6.0",
Expand All @@ -63,6 +64,7 @@
"@types/angular-ui-router": "^1.1.37",
"@types/bootstrap": "^3.3.35",
"@types/core-js": "^0.9.42",
"@types/deep-diff": "^1.0.1",
"@types/intl-tel-input": "0.0.7",
"@types/jasmine": "^2.8.4",
"@types/jasminewd2": "^2.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Api\Model\Shared\ActivityModel;
use Api\Model\Shared\Command\ActivityCommands;
use Api\Model\Shared\Command\ProjectCommands;
use Api\Model\Shared\DeepDiff\DeepDiffDecoder;
use Api\Model\Shared\Mapper\JsonEncoder;
use Api\Model\Shared\ProjectModel;
use Litipk\Jiffy\UniversalTimestamp;
Expand Down Expand Up @@ -129,7 +130,12 @@ public static function updateEntry($projectId, $params, $userId, $mergeQueuePath
if (SendReceiveCommands::isInProgress($projectId)) return false;
}

LexEntryDecoder::decode($entry, $params);
if (array_key_exists('_update_deep_diff', $params)) {
$deepDiff = $params['_update_deep_diff'];
DeepDiffDecoder::applyDeepDiff($entry, $deepDiff);
} else {
LexEntryDecoder::decode($entry, $params);
}

if ($action === 'update') {
$differences = $oldEntry->calculateDifferences($entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ class LexConfiguration
*/
public $userViews;

/** @var integer */
public $pollUpdateIntervalMs;

public function __construct()
{
$this->pollUpdateIntervalMs = 0;

$this->tasks = new MapOf(
function ($data) {
switch ($data['type'] ?? "") {
Expand Down
22 changes: 22 additions & 0 deletions src/Api/Model/Shared/DeepDiff/AddedDiff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Api\Model\Shared\DeepDiff;

use Litipk\Jiffy\UniversalTimestamp;
use Palaso\Utilities\CodeGuard;

class AddedDiff extends DiffBase
{
/** @var mixed */
public $newData;

public function __construct(Array $diff) {
$this->kind = 'N';
$this->path = $diff['path'];
$this->newData = $diff['rhs'];
}

public function getValue() {
return $this->newData;
}
}
26 changes: 26 additions & 0 deletions src/Api/Model/Shared/DeepDiff/ArrayDiff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Api\Model\Shared\DeepDiff;

use Litipk\Jiffy\UniversalTimestamp;
use Palaso\Utilities\CodeGuard;

class ArrayDiff extends DiffBase
{
/** @var integer */
public $idx;

/** @var Array */
public $item;

public function __construct(Array $diff) {
$this->kind = 'A';
$this->path = $diff['path'];
$this->idx = $diff['index'];
$this->item = $diff['item'];
}

public function getValue() {
return $this->item['rhs'];
}
}
139 changes: 139 additions & 0 deletions src/Api/Model/Shared/DeepDiff/DeepDiffDecoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php

namespace Api\Model\Shared\DeepDiff;

use Litipk\Jiffy\UniversalTimestamp;
use Palaso\Utilities\CodeGuard;

class DeepDiffDecoder
{
public static function prepareDeepDiff($diffs) {
$result = [];
foreach (static::reorderPushes($diffs) as $diff) {
$diffInstance = DiffBase::fromDeepDiff($diff);
if ($diffInstance) $result[] = $diffInstance;
}
return $result;
}

public static function reorderPushes($diffs) {
$currentPath = [];
$pushes = [];
$result = [];
foreach ($diffs as $diff) {
if ($diff['kind'] == 'A' && $diff['item']['kind'] == 'N' &&
($currentPath == [] || $currentPath == $diff['path'])) {
$currentPath = $diff['path'];
$pushes[] = $diff;
} else {
if ($pushes) {
foreach (array_reverse($pushes) as $push) {
$result[] = $push;
}
$pushes = [];
$currentPath = [];
}
$result[] = $diff;
}
}
if ($pushes) {
foreach (array_reverse($pushes) as $push) {
$result[] = $push;
}
}
return $result;
}

/**
* Sets the public properties of $model to values from $values[propertyName]
* @param object|MapOf|ArrayOf $model
* @param array $deepDiff An array of diffs from the Javascript deep-diff library.
* @throws \Exception
*/
public static function applyDeepDiff($model, $deepDiff)
{
CodeGuard::checkTypeAndThrow($deepDiff, 'array');
// TODO: Do we need something like this next line from JsonDecoder, or something similar to it?
// $propertiesToIgnore = $this->getPrivateAndReadOnlyProperties($model);
$diffs = static::prepareDeepDiff($deepDiff);
foreach ($diffs as $diff) {
static::applySingleDiff($model, $diff);
}
}

/**
* Sets the public properties of $model to values from $values[propertyName]
* @param object|MapOf|ArrayOf $model
* @param DiffBase $diff A single diff to apply to the model
* @throws \Exception
*/
public static function applySingleDiff($model, $diff)
{
$path = $diff->path;
$allButLast = $path; // This is a copy
$last = array_pop($allButLast);
$isLexValue = false;
if ($last === 'value') {
$isLexValue = true;
$last = array_pop($allButLast);
}
$target = $model;
foreach ($allButLast as $step) {
$target = static::getNextStep($target, $step);
}
if ($diff instanceof ArrayDiff) {
if ($diff->item['kind'] == 'N') {
static::pushValue($target, $last, $diff->getValue());
} elseif ($diff->item['kind'] == 'D') {
if ($target instanceof \ArrayObject) {
array_pop($target[$last]);
} else {
array_pop($target->$last);
}
} else {
// Invalid ArrayDiff; do nothing
}
} else {
static::setValue($target, $last, $diff->getValue());
// TODO: Verify that this works as desired for deletions
}
}

private static function getNextStep($target, $step) {
if ($target instanceof \Api\Model\Shared\Mapper\MapOf && strpos($step, 'customField_') === 0) {
// Custom fields should be created if they do not exist
if (isset($target[$step])) {
return $target[$step];
} else {
if ($target->hasGenerator()) {
return $target->generate([$step]);
} else {
// This will probably fail
return $target[$step];
}
}
} else if ($target instanceof \ArrayObject) {
return $target[$step];
} else {
return $target->$step;
}
}

private static function setValue(&$target, $last, $value) {
if ($target instanceof \Api\Model\Languageforge\Lexicon\LexMultiText) {
$target->form($last, $value);
} else if ($target instanceof \ArrayObject) {
$target[$last] = $value;
} else {
$target->$last = $value;
}
}

private static function pushValue(&$target, $last, $value) {
if ($target instanceof \ArrayObject) {
$target[$last][] = $value;
} else {
$target->$last[] = $value;
}
}
}
22 changes: 22 additions & 0 deletions src/Api/Model/Shared/DeepDiff/DeletedDiff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Api\Model\Shared\DeepDiff;

use Litipk\Jiffy\UniversalTimestamp;
use Palaso\Utilities\CodeGuard;

class DeletedDiff extends DiffBase
{
/** @var mixed */
public $oldData;

public function __construct(Array $diff) {
$this->kind = 'D';
$this->path = $diff['path'];
$this->oldData = $diff['lhs'];
}

public function getValue() {
return null;
}
}
35 changes: 35 additions & 0 deletions src/Api/Model/Shared/DeepDiff/DiffBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Api\Model\Shared\DeepDiff;

use Litipk\Jiffy\UniversalTimestamp;
use Palaso\Utilities\CodeGuard;

class DiffBase
{
/** @var callable The function <object> function($data = null) returns an instance of the object. */
private $_generator;

/** @var char */
public $kind;

/** @var array */
public $path;

public function toMongoPath() {
return join('.', $this->path);
}

public function getValue() {}

public static function fromDeepDiff($deepDiff) {
$kind = $deepDiff['kind'];
switch ($kind) {
case 'N': return new AddedDiff($deepDiff);
case 'D': return new DeletedDiff($deepDiff);
case 'E': return new EditedDiff($deepDiff);
case 'A': return new ArrayDiff($deepDiff);
default: return null;
}
}
}
26 changes: 26 additions & 0 deletions src/Api/Model/Shared/DeepDiff/EditedDiff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Api\Model\Shared\DeepDiff;

use Litipk\Jiffy\UniversalTimestamp;
use Palaso\Utilities\CodeGuard;

class EditedDiff extends DiffBase
{
/** @var mixed */
public $oldData;

/** @var mixed */
public $newData;

public function __construct(Array $diff) {
$this->kind = 'E';
$this->path = $diff['path'];
$this->oldData = $diff['lhs'];
$this->newData = $diff['rhs'];
}

public function getValue() {
return $this->newData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<a class="website-title" href="/">{{ app.website.name }}</a>
</span>
<ul class="nav navbar-nav">
<!-- <li class="nav-item">
<a class="nav-link " href="/app/activity">Activity</a>
</li> -->
<li class="nav-item" uib-dropdown>
<a class="nav-link" uib-dropdown-toggle href id="helpDropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-life-ring"></i> <span>Help</span></a>
<div class="dropdown-menu dropdown-menu-right" uib-dropdown-menu aria-labelledby="helpDropdown">
Expand All @@ -27,7 +24,7 @@
<a class="dropdown-item" target="_blank" href="https://community.software.sil.org/c/language-forge/how-to">Tutorials and How-Tos</a>
<a class="dropdown-item" target="_blank" href="https://community.software.sil.org/c/language-forge">Community Support</a>
<a class="dropdown-item" target="_blank" href="mailto:issues@languageforge.org">Report a Problem<br />(email issues@languageforge.org)</a>
<a class="dropdown-item" href="/releasenotes">Release Notes</a>
<a class="dropdown-item" target="_blank" href="https://github.com/sillsdev/web-languageforge/releases">What's new in the app?</a>
</div>
</li>
<li class="nav-item dropdown" uib-dropdown>
Expand Down
13 changes: 0 additions & 13 deletions src/Site/views/shared/page/releasenotes.html.twig

This file was deleted.

Loading

0 comments on commit 0fd368c

Please sign in to comment.