Add some metadata
authorColeman Watts <coleman@civicrm.org>
Fri, 25 Oct 2019 14:32:24 +0000 (10:32 -0400)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:19 +0000 (19:13 -0700)
ext/afform/core/CRM/Afform/Page/AfformBase.php
ext/afform/gui/afform_gui.php
ext/afform/gui/ang/afGuiEditor.css
ext/afform/gui/ang/afGuiEditor.js
ext/afform/gui/ang/afGuiEditor/canvas.html
ext/afform/gui/ang/afGuiEditor/config-entity.html [new file with mode: 0644]
ext/afform/gui/ang/afGuiEditor/config-form.html [new file with mode: 0644]
ext/afform/gui/ang/afGuiEditor/palette.html

index 3d389528b605092d1f3961d6682536952c11ebfe..3ccc1e50ccdceec78297a9f98236c2ae32da39d4 100644 (file)
@@ -7,6 +7,7 @@ class CRM_Afform_Page_AfformBase extends CRM_Core_Page {
     list ($pagePath, $pageArgs) = func_get_args();
 
     $module = _afform_angular_module_name($pageArgs['afform']);
+    $this->set('afModule', $module);
 
     $loader = new \Civi\Angular\AngularLoader();
     $loader->setModules([$module, 'afformStandalone']);
@@ -18,7 +19,7 @@ class CRM_Afform_Page_AfformBase extends CRM_Core_Page {
     ]);
     $loader->load();
 
-    $afform = civicrm_api4('Afform', 'get', ['checkPermissions' => FALSE, 'where' => [['name', '=', $pageArgs['afform']]], 'select' => ['title']]);
+    $afform = civicrm_api4('Afform', 'get', ['checkPermissions' => FALSE, 'where' => [['name', '=', $module]], 'select' => ['title']]);
 
     if (!empty($afform[0]['title'])) {
       CRM_Utils_System::setTitle(strip_tags($afform[0]['title']));
index 9eef57b07f1bb9fdecf758d17705b1448db6dbc4..72caa9cf6464b371f630019382c6f90eaa4f4176 100644 (file)
@@ -141,30 +141,57 @@ function afform_gui_civicrm_themes(&$themes) {
   _afform_gui_civix_civicrm_themes($themes);
 }
 
-// --- Functions below this ship commented out. Uncomment as required. ---
-
 /**
- * Implements hook_civicrm_preProcess().
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
- *
-function afform_gui_civicrm_preProcess($formName, &$form) {
-
-} // */
+ * Implements hook_civicrm_pageRun().
+ */
+function afform_gui_civicrm_pageRun(&$page) {
+  if (get_class($page) == 'CRM_Afform_Page_AfformBase' && $page->get('afModule') == 'afGuiAdmin') {
+    Civi::resources()->addScriptUrl(Civi::service('asset_builder')->getUrl('af-gui-vars.js'));
+  }
+}
 
 /**
- * Implements hook_civicrm_navigationMenu().
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
+ * Implements hook_civicrm_buildAsset().
  *
-function afform_gui_civicrm_navigationMenu(&$menu) {
-  _afform_gui_civix_insert_navigation_menu($menu, 'Mailings', array(
-    'label' => E::ts('New subliminal message'),
-    'name' => 'mailing_subliminal_message',
-    'url' => 'civicrm/mailing/subliminal',
-    'permission' => 'access CiviMail',
-    'operator' => 'OR',
-    'separator' => 0,
-  ));
-  _afform_gui_civix_navigationMenu($menu);
-} // */
+ * Loads metadata to send to the gui editor.
+ */
+function afform_gui_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
+  if ($asset !== 'af-gui-vars.js') {
+    return;
+  }
+
+  // Things that can't be handled by afform. TODO: Need a better way to do this. Maybe add core metadata about what each entity is for, and filter on that.
+  $entityBlacklist = [
+    'ACL',
+    'ActionSchedule',
+    'ActivityContact',
+    'Afform%',
+    'CaseContact',
+    'EntityTag',
+    'GroupContact',
+    'GroupNesting',
+    'GroupOrganization',
+    'Setting',
+    'System',
+    'UF%',
+  ];
+  $entityApi = Civi\Api4\Entity::get()
+    ->setCheckPermissions(FALSE)
+    ->setSelect(['name', 'description']);
+  foreach ($entityBlacklist as $nono) {
+    $entityApi->addWhere('name', 'NOT LIKE', $nono);
+  }
+
+  $contacts = Civi\Api4\Contact::getFields()
+    ->setCheckPermissions(FALSE)
+    ->setIncludeCustom(TRUE)
+    ->setLoadOptions(TRUE)
+    ->setAction('Create')
+    ->execute();
+
+  $mimeType = 'text/javascript';
+  $content = "CRM.afformAdminData={";
+  $content .= 'entities:' . json_encode((array) $entityApi->execute(), JSON_UNESCAPED_SLASHES) . ',';
+  $content .= 'fields:' . json_encode(['Contact' => (array) $contacts], JSON_UNESCAPED_SLASHES);
+  $content .= '}';
+}
index 190a4abbb5de507c72fb9331b779bab08a8a9dcf..e6464c1b5661b924b4e80279a0e2d47bcf798508 100644 (file)
@@ -2,10 +2,39 @@
   display: flex;
 }
 
-#afGuiEditor-palette {
+#afGuiEditor-main .panel.panel-default {
+  margin-bottom: 0;
+}
+
+#afGuiEditor-main #afGuiEditor-palette {
   flex: 1;
+  margin-right: 5px;
+  box-shadow: 0 3px 18px 0 rgba(48,40,40,0.25);
 }
 
-#afGuiEditor-canvas {
+#afGuiEditor-main #afGuiEditor-canvas {
   flex: 1;
+  margin-left: 5px;
+}
+
+#afGuiEditor-main #afGuiEditor-palette-tabs {
+  width: 110px;
+  position: absolute;
+  left: 0;
+  top: 0;
+}
+
+#afGuiEditor-main #afGuiEditor-palette-tabs li > a {
+  padding: 10px 15px;
+  font-size: 12px;
+}
+
+#afGuiEditor-main #afGuiEditor-palette-tabs .dropdown-menu {
+  max-height: 500px;
+  overflow-y: auto;
+}
+
+#afGuiEditor-main #afGuiEditor-palette-config {
+  margin-left: 110px;
+  box-shadow: none;
 }
index 151ed0166117242b8fe7bf476b9bf1dc5e5ef6e5..14866eb50077c845d7bcd5514287b4125294e9e2 100644 (file)
@@ -13,6 +13,7 @@
         $scope.ts = CRM.ts();
         $scope.afform = null;
         $scope.selectedEntity = null;
+        $scope.meta = CRM.afformAdminData;
         var newForm = {
           title: ts('Untitled Form'),
           layout: {
             label: entityType + ' ' + num
           };
           $scope.afform.layout['#children'].push($scope.entities[entityType + num]);
+          $scope.selectEntity(entityType + num);
         };
 
         $scope.removeEntity = function(entityName) {
           delete $scope.entities[entityName];
           $scope.afform.layout['#children'].splice(_.findIndex($scope.afform.layout['#children'], {'#tag': 'af-entity', name: entityName}), 1);
+          $scope.selectEntity(null);
         };
 
         $scope.selectEntity = function(entityName) {
index b80e6e067849565fa3d5c18a00e7d0384e03681b..103dd04c6e3715af072a496c75b5dc8b92d08c42 100644 (file)
@@ -1,3 +1,6 @@
-<div>
-
+<div class="panel panel-default">
+  <div class="panel-heading">
+    {{ ts('Form Layout') }}
+  </div>
+  <div class="panel-body"></div>
 </div>
diff --git a/ext/afform/gui/ang/afGuiEditor/config-entity.html b/ext/afform/gui/ang/afGuiEditor/config-entity.html
new file mode 100644 (file)
index 0000000..b80e6e0
--- /dev/null
@@ -0,0 +1,3 @@
+<div>
+
+</div>
diff --git a/ext/afform/gui/ang/afGuiEditor/config-form.html b/ext/afform/gui/ang/afGuiEditor/config-form.html
new file mode 100644 (file)
index 0000000..b80e6e0
--- /dev/null
@@ -0,0 +1,3 @@
+<div>
+
+</div>
index 66004be1817a488d20af589d50499e2c73fcfb04..61db37a138ad40d3b982e7b5c6665d584184e830 100644 (file)
@@ -1,16 +1,29 @@
-<ul id="afGuiEditor-tabs" class="nav nav-pills nav-stacked">
+<ul id="afGuiEditor-palette-tabs" class="nav nav-pills nav-stacked">
   <li role="presentation" ng-class="{active: selectedEntity === null}">
     <a href ng-click="selectEntity(null)">{{ ts('Form Settings') }}</a>
   </li>
   <li role="presentation" ng-repeat="entity in entities" ng-class="{active: selectedEntity === entity.name}">
     <a href ng-click="selectEntity(entity.name)">{{ entity.label }}</a>
   </li>
-  <li role="presentation" class="dropdown text-right">
+  <li role="presentation" class="dropdown">
     <a href class="dropdown-toggle" data-toggle="dropdown">
       <i class="crm-i fa-plus"></i>
     </a>
     <ul class="dropdown-menu">
-      <li></li>
+      <li ng-repeat="entity in meta.entities">
+        <a href ng-click="addEntity(entity.name)">{{ entity.name }}</a>
+      </li>
     </ul>
   </li>
 </ul>
+<div id="afGuiEditor-palette-config" class="panel panel-default">
+  <div class="panel-heading">
+    <span ng-if="selectedEntity === null">{{ ts('Form Settings') }}</span>
+    <span ng-if="selectedEntity !== null">{{ entities[selectedEntity].label }}</span>
+    <a href ng-if="selectedEntity !== null" ng-click="removeEntity(selectedEntity)" class="pull-right">
+      <i class="crm-i fa-trash"></i>
+    </a>
+  </div>
+  <div class="panel-body" ng-include="'~/afGuiEditor/config-form.html'" ng-if="selectedEntity === null"></div>
+  <div class="panel-body" ng-include="'~/afGuiEditor/config-entity.html'" ng-if="selectedEntity !== null"></div>
+</div>