diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eb2068b..bc2eda4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,7 +39,7 @@ jobs: NC3_BUILD_DIR: "/opt/nc3" NC3_DOCKER_DIR: "/opt/docker" NC3_GIT_URL: "git://github.com/NetCommons3/NetCommons3.git" - NC3_GIT_BRANCH: "master" + NC3_GIT_BRANCH: "availability" PLUGIN_BUILD_DIR: ${{ github.workspace }} PHP_VERSION: ${{ matrix.php }} MYSQL_VERSION: ${{ matrix.mysql }} @@ -50,6 +50,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Fix up git URLs + run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig + - name: Fix up git URLs run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig diff --git a/Controller/CabinetFilesController.php b/Controller/CabinetFilesController.php index 352d9e5..b12b6c3 100644 --- a/Controller/CabinetFilesController.php +++ b/Controller/CabinetFilesController.php @@ -11,11 +11,13 @@ * * * @author Ryuji AMANO + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @property NetCommonsWorkflow $NetCommonsWorkflow * @property PaginatorComponent $Paginator * @property CabinetFile $CabinetFile + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class CabinetFilesController extends CabinetsAppController { @@ -101,7 +103,9 @@ public function beforeFilter() { 'folder_detail', 'download', 'download_folder', - 'check_download_folder' + 'get_download_counts', + 'check_download_folder', + 'load_download_folder' ); parent::beforeFilter(); $this->_cabinet = $this->Cabinet->find('first', array( @@ -296,6 +300,7 @@ public function download() { * @return CakeResponse|string|void */ public function download_folder() { + $this->response->header('Pragma', 'no-cache'); if (! $this->request->is('post')) { return $this->throwBadRequest(); } @@ -330,12 +335,36 @@ public function download_folder() { return $zipDownloader->download($cabinetFolder['CabinetFile']['filename'] . '.zip'); } +/** + * ファイルのダウンロード数の取得 + * + * @return void + */ + public function get_download_counts() { + $query = [ + 'fields' => [ + 'UploadFile.id', + 'UploadFile.total_download_count', + ], + 'conditions' => [ + 'UploadFile.id' => explode(',', $this->request->query('upload_file_ids')), + ], + 'recursive' => -1 + ]; + $UploadFile = ClassRegistry::init('Files.UploadFile'); + $files = $UploadFile->find('all', $query); + + $this->set('_serialize', ['counts']); + $this->set('counts', $files); + } + /** * フォルダのZIPダウンロードができるか否かチェック * * @return void */ public function check_download_folder() { + $this->response->header('Pragma', 'no-cache'); if (! $this->request->is('post') || ! $this->request->is('ajax')) { return $this->throwBadRequest(); } @@ -373,6 +402,21 @@ protected function _findCabinetFilesByFolderDownload($cabinetFolder) { return $files; } +/** + * ファイルの圧縮ダウンロードのロード処理 + * + * @return void + */ + public function load_download_folder() { + $this->response->header('Pragma', 'no-cache'); + $View = $this->_getViewObject(); + $fileKeys = explode(',', $this->request->query('file_keys')); + + foreach ($fileKeys as $fileKey) { + $View->CabinetFile->setZipDownloadToken($fileKey); + } + } + /** * フォルダのZIPダウンロード前処理 * diff --git a/View/CabinetFiles/folder_detail.ctp b/View/CabinetFiles/folder_detail.ctp index 9e6348c..1c543ad 100644 --- a/View/CabinetFiles/folder_detail.ctp +++ b/View/CabinetFiles/folder_detail.ctp @@ -124,4 +124,6 @@ echo $this->Html->script( ?> + + CabinetFile->loadZipDownload((string)Current::read('Frame.id')); ?> diff --git a/View/CabinetFiles/index.ctp b/View/CabinetFiles/index.ctp index 130ecf1..c372854 100644 --- a/View/CabinetFiles/index.ctp +++ b/View/CabinetFiles/index.ctp @@ -1,6 +1,7 @@ element('NetCommons.javascript_alert'); ?>
NetCommonsHtml->css('/cabinets/css/cabinets.css'); ?> @@ -103,13 +104,22 @@ 'key' => $currentFolder['CabinetFile']['key'], 'frame_id' => Current::read('Frame.id'), )); + $initialValues = array(); + $cacheable = $this->CDNCache->isCacheable(); + foreach ($cabinetFiles as $file) { + if (! $file['CabinetFile']['is_folder']) { + $value = $cacheable ? null : $file['UploadFile']['file']['total_download_count']; + $initialValues[$file['UploadFile']['file']['id']] = $value; + } + } ?> + ng-init="init()">
@@ -192,5 +202,6 @@ + CabinetFile->loadZipDownload((string)Current::read('Frame.id')); ?> diff --git a/View/Elements/CabinetFiles/file_row.ctp b/View/Elements/CabinetFiles/file_row.ctp index 2e60f12..565915f 100644 --- a/View/Elements/CabinetFiles/file_row.ctp +++ b/View/Elements/CabinetFiles/file_row.ctp @@ -44,11 +44,9 @@ 'Password is required to download.' ) ?>"> - - - + + {{downloadCounts[]}} +
_parseAttributes($options); $html .= "" . h($label) . ""; + + $frameId = (string)Current::read('Frame.id'); + if (! isset($this->__zipDolowdKeys[$frameId])) { + $this->__zipDolowdKeys[$frameId] = []; + } + $this->__zipDolowdKeys[$frameId][] = $cabinetFile['CabinetFile']['key']; + return $html; } +/** + * 圧縮ダウンロードリンクのロードタグ出力 + * + * @param string $frameId フレームID + * @return string + */ + public function loadZipDownload($frameId) { + $html = ''; + if (! isset($this->__zipDolowdKeys[$frameId])) { + return $html; + } + + $html .= '
'; + return $html; + } + +/** + * 圧縮ダウンロードのためのTokenセット + * + * @param string $cabinetFileKey ファイルキー + * @return void + */ + public function setZipDownloadToken($cabinetFileKey) { + $cabinetFile = [ + 'CabinetFile' => [ + 'key' => $cabinetFileKey + ], + ]; + $this->zipDownload($cabinetFile, '', []); + } + } diff --git a/webroot/js/cabinets.js b/webroot/js/cabinets.js index 79cbea4..0190e36 100644 --- a/webroot/js/cabinets.js +++ b/webroot/js/cabinets.js @@ -43,8 +43,30 @@ NetCommonsApp.controller('CabinetFile.index', ['$scope', 'NetCommonsModal', '$http', 'NC3_URL', function($scope, NetCommonsModal, $http, NC3_URL) { $scope.moved = {}; - $scope.init = function(parentId) { + $scope.init = function(parentId, frameId, initialValues) { $scope.parent_id = parentId; + + var fileIds = initialValues && Object.keys(initialValues); + if (!fileIds || !fileIds.length) return; + + $scope.downloadCounts = initialValues; + if (initialValues[fileIds[0]] !== null) return; + for (var i = 0; i < fileIds.length; i++) { + initialValues[fileIds[i]] = '-'; + } + + var params = '?frame_id=' + frameId + '&upload_file_ids=' + fileIds.join(','); + $http.get(NC3_URL + '/cabinets/cabinet_files/get_download_counts.json' + params) + .then( + function(response) { + var counts = response.data.counts; + for (var i = 0; i < counts.length; i++) { + var file = counts[i].UploadFile; + $scope.downloadCounts[file.id] = file.total_download_count; + } + }, + function() { + }); }; $scope.moveFile = function(cabinetFileKey, isFolder, data) { @@ -319,4 +341,3 @@ NetCommonsApp.controller('CabinetFile.edit.selectFolder', }; }] ); - diff --git a/webroot/js/cabinets_zip_download.js b/webroot/js/cabinets_zip_download.js index a7f2885..19f25e2 100644 --- a/webroot/js/cabinets_zip_download.js +++ b/webroot/js/cabinets_zip_download.js @@ -40,7 +40,7 @@ NetCommonsApp.controller('CabinetFiles.zipDownload', $event.preventDefault(); var postData = { - CabinetFile: $scope.postData['CabinetFile'], + CabinetFile: $scope.postData['Check']['request'], _Token: $scope.postData['Check']['token'] }; ajaxSendPost('POST', $scope.postData['Check']['action'], postData) @@ -97,7 +97,7 @@ NetCommonsApp.controller('CabinetFiles.zipDownload', }); formElement.append(inputElement); }); - angular.forEach($scope.postData['CabinetFile'], function(value, key) { + angular.forEach($scope.postData['Download']['request'], function(value, key) { var inputElement = $('', { type: 'hidden', name: 'data[CabinetFile][' + key + ']', @@ -110,3 +110,25 @@ NetCommonsApp.controller('CabinetFiles.zipDownload', }; }]); + + +NetCommonsApp.controller('CabinetFiles.loadZipDownload', + ['$scope', '$http', 'NC3_URL', + function($scope, $http, NC3_URL) { + + /** + * イニシャライズ処理 + * + * @return {void} + */ + $scope.load = function(frameId, fileKeys) { + var params = '?frame_id=' + frameId + '&file_keys=' + fileKeys; + $http.get(NC3_URL + '/cabinets/cabinet_files/load_download_folder.json' + params) + .then( + function(response) { + }, + function() { + }); + }; + }] +);