Преглед изворни кода

Ticket #4971 - Build-in API support: Tasks.

AntonLV пре 3 месеци
родитељ
комит
e2b657f8a8

+ 1 - 0
modules/boonex/tasks/classes/BxTasksConfig.php

@@ -300,6 +300,7 @@ class BxTasksConfig extends BxBaseModTextConfig
             'filter_popup' => $sPrefix . '-filter-popup',
             'timer' => $sPrefix . '-timer-',
             'timer_actions' => $sPrefix . '-timer-actions',
+            'timers_actions' => $sPrefix . '-timers-actions',
             'pre_values_popup' => $sPrefix . '-pv-popup-',
         ]);
 

+ 1 - 1
modules/boonex/tasks/classes/BxTasksFormEntry.php

@@ -222,7 +222,7 @@ class BxTasksFormEntry extends BxBaseModTextFormEntry
         if(($sKey = 'OBJECT_REPORTS_TIME') && !empty($CNF[$sKey]) && ($o = BxDolReport::getObjectInstance($CNF[$sKey], $iContentId)))
             $o->onObjectDelete();
 
-        return parent::delete($iContentId);
+        return parent::delete($iContentId, $aContentInfo);
     }
 
     protected function genCustomViewRowValueStickers (&$aInput)

+ 0 - 1
modules/boonex/tasks/classes/BxTasksMenuTimer.php

@@ -41,7 +41,6 @@ class BxTasksMenuTimer extends BxTemplMenuCustom
 
     protected function getMenuItemsRaw ()
     {
-        $sPrefix = str_replace('_', '-', $this->_oModule->_oConfig->getName());
         $sJsObject = $this->_oModule->_oConfig->getJsObject('timer');
 
         $aTimer = $this->_oModule->_oDb->getTimers([

+ 96 - 0
modules/boonex/tasks/classes/BxTasksMenuTimers.php

@@ -0,0 +1,96 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT 
+ * @defgroup    Tasks Tasks
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxTasksMenuTimers extends BxTemplMenuCustom
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    protected $_iProfileId;
+
+    protected $_bShowAsButton;
+    protected $_bShowTitle;
+
+    public function __construct($aObject, $oTemplate = false)
+    {
+        parent::__construct($aObject, $oTemplate);
+
+        $this->_sModule = 'bx_tasks';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+
+        $this->_iProfileId = 0;
+
+        $this->_bShowAsButton = true;
+        $this->_bShowTitle = true;
+    }
+
+    public function setParams($iProfileId)
+    {
+        $this->_iProfileId = $iProfileId;
+    }
+
+    protected function getMenuItemsRaw()
+    {
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('timer');
+
+        return [
+            ['name' => 'clear-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.clearAll(this, ' . $this->_iProfileId . ')', 'target' => '_self', 'title' => _t('_bx_tasks_txt_timers_clear')],
+            ['name' => 'log-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.logAll(this, ' . $this->_iProfileId . ')', 'target' => '_self', 'title' => _t('_bx_tasks_txt_timers_log')],
+        ];
+    }
+
+    protected function _getMenuItemClearAll($aItem)
+    {
+        if($this->_bIsApi) {
+            return array_merge($aItem, [
+                'display_type' => 'callback',
+                'data' => [
+                    'request_url' => $this->_sModule . '/process_timer/&params[]=clear_all&params[]=0&params[]=' . $this->_iProfileId, 
+                    'on_callback' => 'hide'
+                ]
+            ]);
+        }
+
+        return true;
+    }
+
+    protected function _getMenuItemLogAll($aItem)
+    {
+        if($this->_bIsApi) {
+            return array_merge($aItem, [
+                'display_type' => 'callback',
+                'data' => [
+                    'request_url' => $this->_sModule . '/process_timer/&params[]=log_all&params[]=0&params[]=' . $this->_iProfileId, 
+                    'on_callback' => 'hide'
+                ]
+            ]);
+        }
+
+        return true;
+    }
+
+    protected function _getMenuItemDefault($aItem)
+    {
+        if($this->_bIsApi)
+            return $aItem;
+
+        $aItem['class_wrp'] = 'bx-tasks-timer-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
+
+        if($this->_bShowAsButton)
+            $aItem['class_link'] = 'bx-btn' . (isset($aItem['primary']) && (int)$aItem['primary'] == 1 ? ' bx-btn-primary' : '') . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
+
+        if(!$this->_bShowTitle)
+            $aItem['bx_if:title']['condition'] = false;
+
+        return parent::_getMenuItemDefault ($aItem);
+    }
+}
+
+/** @} */

+ 33 - 1
modules/boonex/tasks/classes/BxTasksModule.php

@@ -161,12 +161,16 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
         if(!$this->_iProfileId || $this->_iProfileId != $iProfileId)
             return echoJson(['msg' => _t('_sys_txt_access_denied')]);
 
+        $sName = '';
+        if(($sName = bx_get('name')) !== false)
+            $sName = bx_process_input($sName);
+
         $aResult = $this->serviceProcessTimer($sAction, $iContentId, $iProfileId);
         if($aResult['code'] == 0)
             $aResult = array_merge($aResult, [
                 'content_id' => $iContentId,
                 'profile_id' => $iProfileId,
-                'content' => $this->_oTemplate->getTimer($iContentId, $iProfileId),
+                'content' => $this->_oTemplate->getTimer($iContentId, $iProfileId, $sName),
                 'eval' => $this->_oConfig->getJsObject('timer') . '.onPerformAction' . bx_gen_method_name($sAction) . '(oData)'
             ]);
 
@@ -503,10 +507,38 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
                 $aResult = ['code' => 0];
                 break;
 
+            case 'log_all':
+                $aTimers = $this->getTimersByAuthor($iProfileId);
+
+                $iAffected = 0;
+                foreach($aTimers as $aTimer) {
+                    $aSubResult = $this->serviceProcessTimer('log', $aTimer['content_id'], $iProfileId);
+                    if(($aSubResult['code'] ?? false) === 0)
+                        $iAffected++;
+                }
+
+                if(count($aTimers) == $iAffected)
+                    $aResult = ['code' => 0, 'reload' => 1];
+                break;
+
             case 'clear':
                 if($this->_oDb->deleteTimer(['content_id' => $iContentId, 'profile_id' => $iProfileId]) !== false)
                     $aResult = ['code' => 0];
                 break;
+
+            case 'clear_all':
+                $aTimers = $this->getTimersByAuthor($iProfileId);
+
+                $iAffected = 0;
+                foreach($aTimers as $aTimer) {
+                    $aSubResult = $this->serviceProcessTimer('clear', $aTimer['content_id'], $iProfileId);
+                    if(($aSubResult['code'] ?? false) === 0)
+                        $iAffected++;
+                }
+
+                if(count($aTimers) == $iAffected)
+                    $aResult = ['code' => 0, 'reload' => 1];
+                break;
         }
 
         return $aResult;

+ 25 - 10
modules/boonex/tasks/classes/BxTasksTemplate.php

@@ -9,6 +9,7 @@
  */
 
 require_once('BxTasksMenuTimer.php');
+require_once('BxTasksMenuTimers.php');
 
 class BxTasksTemplate extends BxBaseModTextTemplate
 {
@@ -153,7 +154,8 @@ class BxTasksTemplate extends BxBaseModTextTemplate
 
         $oPermalinks = BxDolPermalinks::getInstance();
 
-        $sKeyTimers = $this->_bIsApi ? 'timers' : 'bx_repeat:timers';
+        $sTimerName = 'hor-sm';
+        $sTimersKey = $this->_bIsApi ? 'timers' : 'bx_repeat:timers';
 
         $aTmplVarsSections = [];
         foreach($aTimers as $aTimer) {
@@ -176,13 +178,13 @@ class BxTasksTemplate extends BxBaseModTextTemplate
             if(!isset($aTmplVarsSections[$sContextType]))
                 $aTmplVarsSections[$sContextType] = [
                     'section_title' => $oModule->getModuleTitle($sContextType),
-                    $sKeyTimers => []
+                    $sTimersKey => []
                 ];
 
-            $aTmplVarsSections[$sContextType][$sKeyTimers][] = array_merge([
+            $aTmplVarsSections[$sContextType][$sTimersKey][] = array_merge([
                 'content_title' => $aContentInfo[$CNF['FIELD_TITLE']],
                 'content_url' => $this->_bIsApi ? bx_api_get_relative_url($sUrl) : $sUrl,
-                'timer' => $this->getTimer($aTimer['content_id'], $iProfileId),
+                'timer' => $this->getTimer($aTimer['content_id'], $iProfileId, $sTimerName),
             ], $this->_bIsApi ? [
                 'context' => $aTmplVarsContext,
             ] : [
@@ -193,22 +195,35 @@ class BxTasksTemplate extends BxBaseModTextTemplate
                 'js_code_timer' => $sJsObject . '.init(' . $aTimer['content_id'] . ', ' . $iProfileId . ', ' . ($aTimer['started'] != 0 ? 1 : 0) . ');'
             ]);
         }
-
         $aTmplVarsSections = array_values($aTmplVarsSections);
+
+        $oActions = new BxTasksMenuTimers([
+            'object' => str_replace('_', '-', $this->_oConfig->getName()) . '_timers',
+            'template' => 'menu_custom_hor.html', 
+            'menu_id' => $this->_oConfig->getHtmlIds('timers_actions'), 
+            'persistent' => 0
+        ]);
+        $oActions->setParams($iProfileId);
+        
         if($this->_bIsApi)
-            return $aTmplVarsSections;
+            return [
+                'sections' => $aTmplVarsSections,
+                'actions' => $oActions->getCodeAPI()
+            ];
 
-        $this->addCss(['timer.css']);
+        $this->addCss(['forms.css', 'timer.css']);
         $this->addJs(['timer.js']);
         return $this->parseHtmlByName('browse_timers.html', [
             'js_code' => $this->getJsCode('timer', [
+                'sName' => $sTimerName,
                 'bMulti' => true
             ]),
-            'bx_repeat:sections' => $aTmplVarsSections
+            'bx_repeat:sections' => $aTmplVarsSections,
+            'actions' => $oActions->getCode()
         ]);
     }
 
-    public function getTimer ($iContentId, $iProfileId)
+    public function getTimer ($iContentId, $iProfileId, $sName = '')
     {
         $CNF = &$this->_oConfig->CNF;
 
@@ -244,7 +259,7 @@ class BxTasksTemplate extends BxBaseModTextTemplate
                 'actions' => $oActions->getCodeAPI()
             ];
 
-        return $this->parseHtmlByName('entry-timer.html', [
+        return $this->parseHtmlByName('entry-timer' . ($sName ? '-' . $sName : '') . '.html', [
             'html_id' => $this->_oConfig->getHtmlIds('timer') . $iContentId . '-' . $iProfileId,
             'hours' => sprintf("%02d", $iHours),
             'minutes' => sprintf("%02d", $iMinutes),

+ 2 - 0
modules/boonex/tasks/install/langs/en.xml

@@ -577,6 +577,8 @@
     <string name="_bx_tasks_txt_timer_clear"><![CDATA[Clear]]></string>
     <string name="_bx_tasks_txt_timer_log"><![CDATA[Log]]></string>
     <string name="_bx_tasks_txt_timer_edit_and_log"><![CDATA[Edit & Log]]></string>
+    <string name="_bx_tasks_txt_timers_clear"><![CDATA[Clear All]]></string>
+    <string name="_bx_tasks_txt_timers_log"><![CDATA[Log All]]></string>
 
     <string name="_bx_tasks_txt_err_cannot_perform_action"><![CDATA[Cannot perform action. Please report.]]></string>
     <string name="_bx_tasks_txt_err_empty_pre_list"><![CDATA[Please select a list to add items to.]]></string>

+ 15 - 1
modules/boonex/tasks/js/timer.js

@@ -17,6 +17,7 @@ function BxTasksTimer(oOptions) {
     this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
     this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
 
+    this._sName = oOptions.sName == undefined ? '' : oOptions.sName;
     this._bMulti = oOptions.bMulti == undefined ? false : oOptions.bMulti;
 
     this._aTimers = [];
@@ -57,7 +58,7 @@ BxTasksTimer.prototype.pauseAll = function () {
         if(!oTimer || !oTimer.length)
             continue;
 
-        this.pause(oTimer.get(0), aKey[0],aKey[1]);
+        this.pause(oTimer.get(0), aKey[0], aKey[1]);
     }
 };
 
@@ -80,6 +81,10 @@ BxTasksTimer.prototype.log = function (oSource, iContentId, iProfileId) {
     this._performAction(oSource, 'log', iContentId, iProfileId);
 };
 
+BxTasksTimer.prototype.logAll = function (oSource, iProfileId) {
+    this._performAction(oSource, 'log_all', 0, iProfileId);
+};
+
 BxTasksTimer.prototype.clear = function (oSource, iContentId, iProfileId) {
     var $this = this;
 
@@ -90,6 +95,14 @@ BxTasksTimer.prototype.clear = function (oSource, iContentId, iProfileId) {
     });
 };
 
+BxTasksTimer.prototype.clearAll = function (oSource, iProfileId) {
+    var $this = this;
+
+    bx_confirm('', function() {
+        $this._performAction(oSource, 'clear_all', 0, iProfileId);
+    });
+};
+
 BxTasksTimer.prototype.onPerformActionStart = function(oData) {
     this._onPerformActionAndSet(oData);
 };
@@ -143,6 +156,7 @@ BxTasksTimer.prototype._performAction = function (oSource, sAction, iContentId,
     $.get(
         this._sActionsUrl + 'process_timer/' + sAction + '/' + iContentId + '/' + iProfileId, 
         {
+            name: $this._sName,
             _t: oDate.getTime()
         },
         function(oData) {

+ 10 - 9
modules/boonex/tasks/template/browse_timers.html

@@ -1,15 +1,15 @@
 __js_code__
-<div class="bx-tasks-timers-sections">
-    <div class="bx-tasks-ts-cnt space-y-4">
+<div class="bx-tasks-timers">
+    <div class="bx-tasks-timers-sections space-y-4">
         <bx_repeat:sections>
-            <div class="bx-tasks-section">
-                <div class="bx-tasks-section-ttl mb-2 text-xl">__section_title__</div>
-                <div class="bx-tasks-section-cnt flex flex-wrap -m-2">
+            <div class="bx-tasks-timers-section">
+                <div class="bx-tasks-ts-ttl mb-2 text-xl">__section_title__</div>
+                <div class="bx-tasks-ts-cnt flex flex-wrap -m-2">
                     <bx_repeat:timers>
-                        <div class="bx-tasks-timer-card-wrp w-1/3">
+                        <div class="bx-tasks-timer-card-wrp w-full">
                             <div class="bx-tasks-timer-card bx-def-box bx-def-box-round-corners m-2">
-                                <div class="bx-tasks-timer-card-cnt p-4">
-                                    <div class="bx-tasks-tc-task flex flex-col text-center">
+                                <div class="bx-tasks-timer-card-cnt flex justify-between items-center p-4">
+                                    <div class="bx-tasks-tc-task flex flex-col">
                                         <div class="bx-tasks-tc-content text-lg font-bold truncate">
                                             <a href="__content_url__">__content_title__</a>
                                         </div>
@@ -19,7 +19,7 @@ __js_code__
                                             </div>
                                         </bx_if:show_context>
                                     </div>
-                                    <div class="bx-tasks-tc-value mt-4">__timer__</div>
+                                    <div class="bx-tasks-tc-value">__timer__</div>
                                 </div>
                             </div>
                             <script>__js_code_timer__</script>
@@ -29,4 +29,5 @@ __js_code__
             </div>
         </bx_repeat:sections>
     </div>
+    <div class="bx-tasks-timers-actions mt-4">__actions__</div>
 </div>

+ 18 - 4
modules/boonex/tasks/template/css/timer.css

@@ -1,22 +1,36 @@
+/*-- Timers --*/
+.bx-tasks-timers-actions .bx-menu-custom {
+    justify-content: flex-end;
+
+    margin: -0.25rem -0.5rem;
+}
+.bx-tasks-timers-actions .bx-menu-custom li {
+    margin: 0.25rem 0.5rem;
+}
+.bx-tasks-timers-actions .bx-menu-custom li a {
+    padding-left: 1.5rem;
+    padding-right: 1.5rem;
+}
+
 /*-- Timer --*/
-.bx-tasks-actions .bx-menu-custom {
+.bx-tasks-timer-actions .bx-menu-custom {
     flex-wrap: wrap;
     justify-content: center;
 
     margin: -0.25rem -0.5rem;
 }
 
-.bx-tasks-actions .bx-menu-custom li {
+.bx-tasks-timer-actions .bx-menu-custom li {
     margin: 0.25rem 0.5rem;
 }
 
-.bx-tasks-actions .bx-menu-custom li a {
+.bx-tasks-timer-actions .bx-menu-custom li a {
     padding-left: 1.5rem;
     padding-right: 1.5rem;
 }
 
 /*-- Timer Card --*/
-.bx-tasks-timer-card .bx-tasks-actions .bx-menu-custom li a {
+.bx-tasks-timer-card .bx-tasks-timer-actions .bx-menu-custom li a {
     padding-left: 1.0rem;
     padding-right: 1.0rem;
 }

+ 10 - 0
modules/boonex/tasks/template/entry-timer-hor-sm.html

@@ -0,0 +1,10 @@
+<div id="__html_id__" class="bx-tasks-timer">
+    <div class="bx-tasks-timer-cnt flex items-center">
+        <div class="bx-tasks-timer-content flex flex-row text-lg">
+            <div class="bx-tasks-th">__hours__</div><div>:</div>
+            <div class="bx-tasks-tm">__minutes__</div><div>:</div>
+            <div class="bx-tasks-ts">__seconds__</div>
+        </div>
+        <div class="bx-tasks-timer-actions ml-4">__actions__</div>
+    </div>
+</div>

+ 2 - 2
modules/boonex/tasks/template/entry-timer.html

@@ -1,10 +1,10 @@
 <div id="__html_id__" class="bx-tasks-timer">
     <div class="bx-tasks-timer-cnt">
-        <div class="bx-tasks-content flex flex-row justify-center text-2xl">
+        <div class="bx-tasks-timer-content flex flex-row justify-center text-2xl">
             <div class="bx-tasks-th">__hours__</div><div>:</div>
             <div class="bx-tasks-tm">__minutes__</div><div>:</div>
             <div class="bx-tasks-ts">__seconds__</div>
         </div>
-        <div class="bx-tasks-actions mt-2">__actions__</div>
+        <div class="bx-tasks-timer-actions mt-2">__actions__</div>
     </div>
 </div>