Share Document Library Extension Points
 Mike Hatfield • Senior UI Engineer • twitter @mikehatfield
Agenda

1    Overview: What were the Swift goals?
2    Data Webscript Refactoring
3    Share Refactoring
4    Indicator icons
5    Metadata templates
6    Actions
7    Evaluators
Overview: What were the Swift goals?

•  To give developers, partners and
   implementors the ability to customize
   & extend the Share Document Library
   without having to either write or
   duplicate large amounts of code.
•  Allowing modules such as Web
   QuickStart and Records Management
   to be fully isolated from “core” Share
   code.
V3.4 Unofficial Extension Points
                                 Custom UI
         New Filters
                                     New Actions




                                 Custom UI
              New Filters
                                      New Actions


    Custom UI
                                              New Actions


New Actions




        New Filters
V4.0 Extension Points

•  Repository tier
  o    All node properties & aspects retrieved
  o    Custom property decorators
•  Web tier
  o    Definitions appear ONCE in Share config!
  o    Status indicators
  o    Metadata templates for custom property
       rendering
  o    Actions redefined and regrouped
V4.0 Extension Points

Custom UI                                             (New Actions)

                                                   (Custom Metadata)




Custom UI                                              New Actions

New Filters                                        Custom Metadata




                                                       New Actions
New Filters
                                                    Custom Response


                      Custom Property Decorators
Repository Tier: Refactored Webscripts

•  “documentlibrary-v2” data webscripts
•  evaluator.lib.js
  o    Much smaller
  o    Only handles links and working copies
•  filters.lib.js still in use, but “path” queries
   no longer use Lucene
•  Most of the work done via
  o    org.alfresco.repo.jscript.ApplicationScriptUtils
  o    and SlingshotDocLibCustomResponse
Repository Tier: Property Decorators

•  applicationScriptUtils bean
  o    <property name="decoratedProperties">
       <map>
         <entry key="cm:creator">
           <ref bean="usernamePropertyDecorator"/>
         </entry>
         …
       </map>


  o    Augment JSON response for that property
        •  userName
        •  firstName, lastName, displayName
Repository Tier: Custom Response

•  slingshotDocLibCustomResponse bean
  o    <property name=”customResponses">
       <map>
         <entry key=”vtiServer">
           <ref bean="doclibCustomVtiServer"/>
         </entry>
         …
       </map>


  o    Populates custom JSON response in metadata /
       custom section
        •  port, host
        •  or null if the module is not installed
Web Tier: Indicators

•  Configured & evaluated on web tier
 <indicator id="google-docs-locked" index="10">
   <evaluator>evaluator.doclib.indicator.googleDocsLocked</evaluator>
   <labelParam index="0">{jsNode.properties.owner.displayName}</labelParam>
   <labelParam index="1">{jsNode.properties.owner.userName}</labelParam>
   <override>locked</override>
 </indicator>


  o    evaluator(s) - Bean Id of existing or custom JSON
       evaluator
  o    labelParam(s) - Substituted at runtime from node
  o    override(s) – deactivates existing indicator
Document Library: Metadata Templates

•  Two predefined templates
  <metadata-templates>
   <!-- Default (fallback) -->
   <template id="default">
     <line index="10" id="date">{date}{size}</line>
     <line index="20" id="description” view=“detailed”>{description}</line>
     <line index="30" id="tags” view=“detailed”>{tags}</line>
     <line index="40" id="categories" view=“detailed”
           evaluator="evaluator.doclib.metadata.hasCategories">{categories}</line>
     <line index="50" id="social" view=“detailed”>{social}</line>
   </template>

    <!-- Working Copies -->
    <template id="isWorkingCopy">
      <evaluator>evaluator.doclib.metadata.isWorkingCopy</evaluator>
      <line index="10" id="date">{date}{size}</line>
      <line index="20" id="description" view=“detailed”>{description}</line>
    </template>
  </metadata-templates>
Document Library: Metadata Templates
  <template id="isPhoto">
    <evaluator>evaluator.doclib.metadata.hasExif</evaluator>
    <line index="10" id="date”>{date}{size}</line>
    <line index="20" id="exposure” simpleView=“true”
                     evaluator="evaluator.doclib.metadata.hasExposure">
          {exposure exif.label.exposure}
    </line>
    <line index="30" id="description”>{description}</line>
  </template>



•  Optional label (space-separated)
•  Optional line-based evaluator
•  Simple and/or Detailed view
Document Library: Metadata Templates

•  Metadata placeholders can be:
  o    Node property names
        •  cm_description (can omit prefix for “cm”)
        •  exif_fNumber
  o    JavaScript renderer, e.g. {exposure}
       YAHOO.Bubbling.fire("registerRenderer",
       {
         propertyName: "exposure",
         renderer: function exif_renderer(record, label)
         {
           return "...";
         }
       });
Document Library: Actions

•  Configured & evaluated on web tier
   <!-- Edit online -->
   <action id="document-edit-online"
             type="javascript"
             label="actions.document.edit-online">
     <param name="function">onActionEditOnline</param>
     <permissions>
       <permission allow="true">Write</permission>
     </permissions>
   <evaluator>evaluator.doclib.action.onlineEdit</evaluator>
   </action>
Document Library: Actions

•  Three main action types:
  o    “link” – external link or link to content
  o    “pagelink” – to another Share page (e.g. details)
  o    “javascript” – client-side action
  o    Configurable javascript actions
        •  onActionSimpleRepoAction
           e.g. Simple Workflow approve/reject
        •  onActionFormDialog
           e.g. Transform (to image), Run Action
           –  Not assigned an actionGroup OOTB
Document Library: JavaScript Actions

•  Sometimes client-side code is required
  o    e.g. gathering user input
•  Register a custom action handler
         YAHOO.Bubbling.fire("registerAction",
         {
           actionName: ”onActionGeotag",
           fn: function geotag_onActionGeotag(record)
           {
             …
           }
         });
Document Library: Action Groups

•  Reference & order actions
    <actionGroups>
     <actionGroup id="document-browse">
       ...
       <action index="200" id="document-edit-online" />
       …
     </actionGroup>

     <actionGroup id="document-details">
     <actionGroup id=“folder-browse”>
     ...

•  Override label, icon for action re-use
Document Library: Action Groups

•  Default groups
   <actionGroup id="document-browse">
   <actionGroup id="document-details">
   <actionGroup id="folder-browse">
   <actionGroup id="folder-details">
   <actionGroup id="document-link-browse">
   <actionGroup id="document-link-details">
   <actionGroup id="folder-link-browse">
   <actionGroup id="folder-link-details">


•  Group name calculated in overridable
 web tier “calculateActionGroupId”
 function
Document Library: Action Examples

•  Completely disable an action
   <config evaluator="string-compare" condition="DocLibActions">
     <actions>
      <action id="document-upload-new-version">
        <evaluator>evaluator.doclib.action.disableAction</evaluator>
      </action>
     <actions>
   </config>


•  …or conditionally (e.g. WCMQS site)
   <!-- Publish document: Disable for non-WCMQS sites -->
   <action id="document-publish">
     <evaluator negate="true">
         wcmqs.evaluator.doclib.action.isWebsiteContainerType
     </evaluator>
   </action>
Document Library: Web Tier Evaluators

•  Simple Java class: extend BaseEvaluator,
     implement evaluator, return boolean
•    Predefined evaluators:
     o    Has aspect            o    Always false
     o    Is mimetype           o    Value-based
     o    Property Not Null     o    Metadata value
     o    Site Preset           o    Is browser (type)
     o    Site / No Site        o    Is Portlet mode
     o    Container type
     o    Node type           Also evaluator chaining
Client-side Extensions

•  Include via config extension
 <config evaluator="string-compare" condition="DocLibCustom">
   <dependencies>
     <css src="my-custom-action.css" />
     <js src="my-custom-action.js" />
   </dependencies>
 </config>


•  Relative to /share/res servlet
•  Included after OOTB code to allow for
 customization and extension
Client-side Extensions

•  Custom template
    YAHOO.Bubbling.fire("registerRenderer",
    {
      propertyName: "exposure",
      renderer: function exif_renderer(record, label)
      …



•  Custom action
    YAHOO.Bubbling.fire("registerAction",
    {
      actionName: "onActionGeotag",
      fn: function geotag_onActionGeotag(record)
      …
Demo
Summary

•  All indicator, metadata template and
   action config centralised &
   extendable.
•  Completely refactored Document
   Library web tier actions config – not
   backward compatible with pre-4.0.
•  However, old Remote API “doclist”
   data webscripts still in-place.
Questions?
The open platform for
social content management.

CUST-1 Share Document Library Extension Points

  • 1.
    Share Document LibraryExtension Points Mike Hatfield • Senior UI Engineer • twitter @mikehatfield
  • 2.
    Agenda 1  Overview: What were the Swift goals? 2  Data Webscript Refactoring 3  Share Refactoring 4  Indicator icons 5  Metadata templates 6  Actions 7  Evaluators
  • 3.
    Overview: What werethe Swift goals? •  To give developers, partners and implementors the ability to customize & extend the Share Document Library without having to either write or duplicate large amounts of code. •  Allowing modules such as Web QuickStart and Records Management to be fully isolated from “core” Share code.
  • 4.
    V3.4 Unofficial ExtensionPoints Custom UI New Filters New Actions Custom UI New Filters New Actions Custom UI New Actions New Actions New Filters
  • 5.
    V4.0 Extension Points • Repository tier o  All node properties & aspects retrieved o  Custom property decorators •  Web tier o  Definitions appear ONCE in Share config! o  Status indicators o  Metadata templates for custom property rendering o  Actions redefined and regrouped
  • 6.
    V4.0 Extension Points CustomUI (New Actions) (Custom Metadata) Custom UI New Actions New Filters Custom Metadata New Actions New Filters Custom Response Custom Property Decorators
  • 7.
    Repository Tier: RefactoredWebscripts •  “documentlibrary-v2” data webscripts •  evaluator.lib.js o  Much smaller o  Only handles links and working copies •  filters.lib.js still in use, but “path” queries no longer use Lucene •  Most of the work done via o  org.alfresco.repo.jscript.ApplicationScriptUtils o  and SlingshotDocLibCustomResponse
  • 8.
    Repository Tier: PropertyDecorators •  applicationScriptUtils bean o  <property name="decoratedProperties"> <map> <entry key="cm:creator"> <ref bean="usernamePropertyDecorator"/> </entry> … </map> o  Augment JSON response for that property •  userName •  firstName, lastName, displayName
  • 9.
    Repository Tier: CustomResponse •  slingshotDocLibCustomResponse bean o  <property name=”customResponses"> <map> <entry key=”vtiServer"> <ref bean="doclibCustomVtiServer"/> </entry> … </map> o  Populates custom JSON response in metadata / custom section •  port, host •  or null if the module is not installed
  • 10.
    Web Tier: Indicators • Configured & evaluated on web tier <indicator id="google-docs-locked" index="10"> <evaluator>evaluator.doclib.indicator.googleDocsLocked</evaluator> <labelParam index="0">{jsNode.properties.owner.displayName}</labelParam> <labelParam index="1">{jsNode.properties.owner.userName}</labelParam> <override>locked</override> </indicator> o  evaluator(s) - Bean Id of existing or custom JSON evaluator o  labelParam(s) - Substituted at runtime from node o  override(s) – deactivates existing indicator
  • 11.
    Document Library: MetadataTemplates •  Two predefined templates <metadata-templates> <!-- Default (fallback) --> <template id="default"> <line index="10" id="date">{date}{size}</line> <line index="20" id="description” view=“detailed”>{description}</line> <line index="30" id="tags” view=“detailed”>{tags}</line> <line index="40" id="categories" view=“detailed” evaluator="evaluator.doclib.metadata.hasCategories">{categories}</line> <line index="50" id="social" view=“detailed”>{social}</line> </template> <!-- Working Copies --> <template id="isWorkingCopy"> <evaluator>evaluator.doclib.metadata.isWorkingCopy</evaluator> <line index="10" id="date">{date}{size}</line> <line index="20" id="description" view=“detailed”>{description}</line> </template> </metadata-templates>
  • 12.
    Document Library: MetadataTemplates <template id="isPhoto"> <evaluator>evaluator.doclib.metadata.hasExif</evaluator> <line index="10" id="date”>{date}{size}</line> <line index="20" id="exposure” simpleView=“true” evaluator="evaluator.doclib.metadata.hasExposure"> {exposure exif.label.exposure} </line> <line index="30" id="description”>{description}</line> </template> •  Optional label (space-separated) •  Optional line-based evaluator •  Simple and/or Detailed view
  • 13.
    Document Library: MetadataTemplates •  Metadata placeholders can be: o  Node property names •  cm_description (can omit prefix for “cm”) •  exif_fNumber o  JavaScript renderer, e.g. {exposure} YAHOO.Bubbling.fire("registerRenderer", { propertyName: "exposure", renderer: function exif_renderer(record, label) { return "..."; } });
  • 14.
    Document Library: Actions • Configured & evaluated on web tier <!-- Edit online --> <action id="document-edit-online" type="javascript" label="actions.document.edit-online"> <param name="function">onActionEditOnline</param> <permissions> <permission allow="true">Write</permission> </permissions> <evaluator>evaluator.doclib.action.onlineEdit</evaluator> </action>
  • 15.
    Document Library: Actions • Three main action types: o  “link” – external link or link to content o  “pagelink” – to another Share page (e.g. details) o  “javascript” – client-side action o  Configurable javascript actions •  onActionSimpleRepoAction e.g. Simple Workflow approve/reject •  onActionFormDialog e.g. Transform (to image), Run Action –  Not assigned an actionGroup OOTB
  • 16.
    Document Library: JavaScriptActions •  Sometimes client-side code is required o  e.g. gathering user input •  Register a custom action handler YAHOO.Bubbling.fire("registerAction", { actionName: ”onActionGeotag", fn: function geotag_onActionGeotag(record) { … } });
  • 17.
    Document Library: ActionGroups •  Reference & order actions <actionGroups> <actionGroup id="document-browse"> ... <action index="200" id="document-edit-online" /> … </actionGroup> <actionGroup id="document-details"> <actionGroup id=“folder-browse”> ... •  Override label, icon for action re-use
  • 18.
    Document Library: ActionGroups •  Default groups <actionGroup id="document-browse"> <actionGroup id="document-details"> <actionGroup id="folder-browse"> <actionGroup id="folder-details"> <actionGroup id="document-link-browse"> <actionGroup id="document-link-details"> <actionGroup id="folder-link-browse"> <actionGroup id="folder-link-details"> •  Group name calculated in overridable web tier “calculateActionGroupId” function
  • 19.
    Document Library: ActionExamples •  Completely disable an action <config evaluator="string-compare" condition="DocLibActions"> <actions> <action id="document-upload-new-version"> <evaluator>evaluator.doclib.action.disableAction</evaluator> </action> <actions> </config> •  …or conditionally (e.g. WCMQS site) <!-- Publish document: Disable for non-WCMQS sites --> <action id="document-publish"> <evaluator negate="true"> wcmqs.evaluator.doclib.action.isWebsiteContainerType </evaluator> </action>
  • 20.
    Document Library: WebTier Evaluators •  Simple Java class: extend BaseEvaluator, implement evaluator, return boolean •  Predefined evaluators: o  Has aspect o  Always false o  Is mimetype o  Value-based o  Property Not Null o  Metadata value o  Site Preset o  Is browser (type) o  Site / No Site o  Is Portlet mode o  Container type o  Node type Also evaluator chaining
  • 21.
    Client-side Extensions •  Includevia config extension <config evaluator="string-compare" condition="DocLibCustom"> <dependencies> <css src="my-custom-action.css" /> <js src="my-custom-action.js" /> </dependencies> </config> •  Relative to /share/res servlet •  Included after OOTB code to allow for customization and extension
  • 22.
    Client-side Extensions •  Customtemplate YAHOO.Bubbling.fire("registerRenderer", { propertyName: "exposure", renderer: function exif_renderer(record, label) … •  Custom action YAHOO.Bubbling.fire("registerAction", { actionName: "onActionGeotag", fn: function geotag_onActionGeotag(record) …
  • 23.
  • 24.
    Summary •  All indicator,metadata template and action config centralised & extendable. •  Completely refactored Document Library web tier actions config – not backward compatible with pre-4.0. •  However, old Remote API “doclist” data webscripts still in-place.
  • 25.
  • 26.
    The open platformfor social content management.