Commit 0a02063d authored by colemanw's avatar colemanw
Browse files

Merge branch 'master-statuses' into 'master'

Add "has_local" and "has_packaged." Adjust "Revert" button.

See merge request extensions/afform!15
parents afd8f7df 7496c8b2
......@@ -152,6 +152,21 @@ class CRM_Afform_AfformScanner {
}
}
public function getComputedFields($name) {
// Ex: $allPaths['viewIndividual'][0] == '/var/www/foo/afform/view-individual'].
$allPaths = $this->findFilePaths()[$name];
// $activeLayoutPath = $this->findFilePath($name, self::LAYOUT_FILE);
// $activeMetaPath = $this->findFilePath($name, self::METADATA_FILE);
$localLayoutPath = $this->createSiteLocalPath($name, self::LAYOUT_FILE);
$localMetaPath = $this->createSiteLocalPath($name, self::METADATA_FILE);
$fields = [];
$fields['has_local'] = file_exists($localLayoutPath) || file_exists($localMetaPath);
$fields['has_packaged'] = ($fields['has_local'] && count($allPaths) > 1)
|| (!$fields['has_local'] && count($allPaths) > 0);
return $fields;
}
/**
* @param string $formName
* Ex: 'view-individual'
......
......@@ -19,6 +19,7 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
$values = [];
foreach ($names as $name) {
$record = $scanner->getMeta($name);
$record = array_merge($record, $scanner->getComputedFields($name));
$layout = $this->_isFieldSelected('layout') ? $scanner->getLayout($name) : NULL;
if ($layout !== NULL) {
// FIXME check for validity?
......
......@@ -86,7 +86,7 @@ class Afform extends AbstractEntity {
public static function getFields() {
return new BasicGetFieldsAction('Afform', __FUNCTION__, function($self) {
return [
$fields = [
[
'name' => 'name',
],
......@@ -111,6 +111,17 @@ class Afform extends AbstractEntity {
'name' => 'layout',
],
];
if ($self->getAction() === 'get') {
$fields[] = [
'name' => 'has_local',
];
$fields[] = [
'name' => 'has_packaged',
];
}
return $fields;
});
}
......
......@@ -35,6 +35,8 @@ trait AfformSaveTrait {
$fields = \Civi\Api4\Afform::getfields()->setCheckPermissions(FALSE)->addSelect('name')->execute()->column('name');
unset($fields[array_search('layout', $fields)]);
unset($fields[array_search('name', $fields)]);
unset($fields[array_search('has_local', $fields)]);
unset($fields[array_search('has_packaged', $fields)]);
$orig = \Civi\Api4\Afform::get()->setCheckPermissions(FALSE)->addWhere('name', '=', $item['name'])->setSelect($fields)->execute()->first();
}
......
......@@ -2,7 +2,7 @@
<i class="crm-i fa-plus"></i> {{ ts('New Form') }}
</a>
<div
af-api4="['Afform', 'get', {select: ['name','title','is_public','server_route'], orderBy: {name:'ASC'}}]"
af-api4="['Afform', 'get', {select: ['name','title','is_public','server_route','has_local','has_packaged'], orderBy: {name:'ASC'}}]"
af-api4-ctrl="listCtrl">
<div ng-if="apiData.result.length == 0">
......@@ -36,8 +36,17 @@
<a af-api4-action="['Afform', 'revert', {where: [['name','=', availForm.name]]}]"
af-api4-start-msg="ts('Reverting...')"
af-api4-success-msg="ts('Reverted')"
af-api4-success="listCtrl.refresh()"
class="btn btn-xs btn-default"
ng-if="availForm.has_local && availForm.has_packaged"
>{{ts('Revert')}}</a>
<a af-api4-action="['Afform', 'revert', {where: [['name','=', availForm.name]]}]"
af-api4-start-msg="ts('Deleting...')"
af-api4-success-msg="ts('Deleted')"
af-api4-success="listCtrl.refresh()"
class="btn btn-xs btn-default"
ng-if="availForm.has_local && !availForm.has_packaged"
>{{ts('Delete')}}</a>
</td>
</tr>
</tbody>
......
<div
af-api4="['Afform', 'get', {select: ['name','title','is_public','server_route'], orderBy: {name:'ASC'}}]"
af-api4="['Afform', 'get', {select: ['name','title','is_public','server_route', 'has_local', 'has_packaged'], orderBy: {name:'ASC'}}]"
af-api4-ctrl="listCtrl">
<div ng-if="apiData.result.length == 0">
......@@ -33,8 +33,17 @@
<a af-api4-action="['Afform', 'revert', {where: [['name','=', availForm.name]]}]"
af-api4-start-msg="ts('Reverting...')"
af-api4-success-msg="ts('Reverted')"
af-api4-success="listCtrl.refresh()"
class="btn btn-xs btn-default"
ng-if="availForm.has_local && availForm.has_packaged"
>{{ts('Revert')}}</a>
<a af-api4-action="['Afform', 'revert', {where: [['name','=', availForm.name]]}]"
af-api4-start-msg="ts('Deleting...')"
af-api4-success-msg="ts('Deleted')"
af-api4-success="listCtrl.refresh()"
class="btn btn-xs btn-default"
ng-if="availForm.has_local && !availForm.has_packaged"
>{{ts('Delete')}}</a>
</td>
</tr>
</tbody>
......
......@@ -59,6 +59,8 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
$this->assertEquals($get($originalMetadata, 'description'), $get($result[0], 'description'), $message);
$this->assertEquals($get($originalMetadata, 'server_route'), $get($result[0], 'server_route'), $message);
$this->assertTrue(is_array($result[0]['layout']), $message);
$this->assertEquals(TRUE, $get($result[0], 'has_packaged'), $message);
$this->assertEquals(FALSE, $get($result[0], 'has_local'), $message);
$message = 'After updating with Afform.create, the revised data should be returned';
$result = Civi\Api4\Afform::update()
......@@ -75,6 +77,8 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
$this->assertEquals('The temporary description', $get($result[0], 'description'), $message);
$this->assertEquals($get($originalMetadata, 'server_route'), $get($result[0], 'server_route'), $message);
$this->assertTrue(is_array($result[0]['layout']), $message);
$this->assertEquals(TRUE, $get($result[0], 'has_packaged'), $message);
$this->assertEquals(TRUE, $get($result[0], 'has_local'), $message);
Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
$message = 'After reverting, the final Afform.get should return default data';
......@@ -84,6 +88,8 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
$this->assertEquals($get($originalMetadata, 'description'), $get($result[0], 'description'), $message);
$this->assertEquals($get($originalMetadata, 'server_route'), $get($result[0], 'server_route'), $message);
$this->assertTrue(is_array($result[0]['layout']), $message);
$this->assertEquals(TRUE, $get($result[0], 'has_packaged'), $message);
$this->assertEquals(FALSE, $get($result[0], 'has_local'), $message);
}
public function getFormatExamples() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment