Uploaded image for project: 'CMS'
  1. CMS
  2. CMS-10123

[ScriptTool] [Refactor] Make it more clear the purpose of JS params "selection" and "model"

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.3.0
    • Fix Version/s: 4.3.0
    • Component/s: None
    • Labels:
      None
    • Sprint:
      4.3 M5

      Description

      While I was reading some code of Ametys.plugins.cms.search.ScriptTool, in line 316 there was:

      Ametys.data.ServerComm.callMethod({
          role: 'org.ametys.cms.scripts.CmsScriptHandler',
          methodName: 'executeScript',
          parameters: [{
              script: this._editor.getValue() || null,
              selection: this._convertedSelection || '',
              model: "search-ui.default"
          }],
      

      And I was wondering why we were passing "selection" and "model" parameters as in server code, org.ametys.plugins.core.ui.script.ScriptHandler.executeScript(Map<String, Object>) it does:

      return executeScript((String) arguments.get("script"));
      

      But in fact, it was used by CmsScriptHandler and CmsScriptBinding:

      String defaultModelId = Optional.ofNullable(_serverCommHelper.getJsParameters())
                                              .map(params -> params.get("parameters"))
                                              .map(List.class::cast)
                                              .map(list -> list.get(0))
                                              .map(Map.class::cast)
                                              .map(params -> (String) params.get("model"))
                                              .orElse(null);
      
      Map<String, Object> jsParameters = _serverCommHelper.getJsParameters();
      Collection<String> selection = Optional.ofNullable(jsParameters.getOrDefault("parameters", null))
                      .map(List.class::cast)
                      .map(l -> l.get(0))
                      .map(Map.class::cast)
                      .map(map -> (Collection<String>) map.getOrDefault(REQUEST_PARAM_SELECTION, null))
                      .orElse(null);
      

      I found it not very clear and explicit, using ServerCommHelper here is too invisible in my opinion.
      And I could have removed them if I did not try to know more.
      So the purpose of this issue is just to do a little refactor to make those kind of parameters them more clear, and visible by the compiler.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                sprieul Simon Prieul
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: