Commit 8a246556 authored by schrieveslaach's avatar schrieveslaach

Improve display of member's files

parent 42cff0ca
Pipeline #37773985 passed with stages
in 5 minutes and 48 seconds
......@@ -4,6 +4,7 @@ namespace OCA\SPGVerein\AppInfo;
use \OCP\AppFramework\App;
use \OCA\SPGVerein\Controller\ClubController;
use \OCA\SPGVerein\Controller\FileController;
use \OCA\SPGVerein\Controller\PageController;
use OCA\SPGVerein\Repository\Club;
......@@ -29,6 +30,12 @@ class Application extends App {
);
});
$container->registerService('FileController', function ($c) {
return new FileController(
$c->query('AppName'), $c->query('Request'), $c->query('Club')
);
});
/**
* Repository Layer
*/
......
......@@ -8,6 +8,7 @@ $application->registerRoutes($this, array(
array('name' => 'page#index', 'url' => '/', 'verb' => 'GET'),
array('name' => 'club#listClubs', 'url' => '/clubs', 'verb' => 'GET'),
array('name' => 'club#listMembers', 'url' => '/members/{club}/{grouping}', 'verb' => 'GET'),
array('name' => 'club#listCities', 'url' => '/cities/{club}', 'verb' => 'GET')
array('name' => 'club#listCities', 'url' => '/cities/{club}', 'verb' => 'GET'),
array('name' => 'file#downloadFile', 'url' => '/files/{club}/{memberId}/{filename}', 'verb' => 'GET')
)
));
......@@ -12,7 +12,7 @@
</select>
</section>
<members v-bind:members="members" v-bind:cities="cities"></members>
<members v-bind:members="members" v-bind:cities="cities" :club="selectedClub"></members>
</div>
</div>
</template>
......
......@@ -8,8 +8,8 @@
<br v-if="Object.keys(member.files).length > 0">
<p class="docs" v-if="Object.keys(member.files).length > 0">
<a class="button" :href="`/remote.php/webdav${member.files[index]}`" v-for="index in Object.keys(member.files)">
<font-awesome-icon icon="file"/> {{ index }}
<a class="button" :href="getFileUrl(file)" v-for="file in member.files">
<font-awesome-icon icon="file"/> {{ file }}
</a>
</p>
</div>
......@@ -26,6 +26,15 @@
props: {
member: {
type: Object
},
club: {
type: String
}
},
methods: {
getFileUrl(file) {
return OC.generateUrl(`/apps/spgverein/files/${this.club}/${this.member.id}/${file}`);
}
}
}
......
......@@ -20,7 +20,7 @@
</div>
<div class="members">
<member v-bind:member="member" v-for="member in getMembersOf(city)"></member>
<member :club="club" v-bind:member="member" v-for="member in getMembersOf(city)"></member>
</div>
</section>
</div>
......@@ -51,6 +51,9 @@
},
cities: {
type: Array
},
club: {
type: String
}
},
......
<?php
namespace OCA\SPGVerein\Controller;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\IRequest;
use OCP\AppFramework\Controller;
use OCA\SPGVerein\Repository\Club;
class FileController extends Controller {
private $club;
public function __construct($AppName, IRequest $request, Club $club) {
parent::__construct($AppName, $request);
$this->club = $club;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function downloadFile(string $club, string $memberId, string $filename): Response {
foreach ($this->club->getAllMembers($club) as $member) {
if ($member->getId() === intval($memberId)) {
foreach ($member->getFiles() as $file) {
if ($file->getName() === $filename) {
$response = new FileDisplayResponse($file);
$response->setHeaders(array(
"Content-type" => $file->getMimeType()
));
return $response;
}
}
}
}
return new NotFoundResponse();
}
}
\ No newline at end of file
......@@ -66,10 +66,7 @@ class Member implements JsonSerializable
$files = array();
foreach ($this->files as $file) {
$files[$file->getName()] = str_replace(
$file->getMountPoint()->getMountPoint() . "files",
"",
$file->getPath());
array_push($files, $file->getName());
}
return $files;
......@@ -136,4 +133,9 @@ class Member implements JsonSerializable
{
array_push($this->files, $file);
}
public function getFiles(): array
{
return $this->files;
}
}
......@@ -56,15 +56,12 @@ class Club
try {
$id = str_pad($member->getId(), 10, "0", STR_PAD_LEFT);
$searchPath = $clubFile->getParent()->getPath() . '/archiv/' . $id;
$searchPath = '/archiv/' . $id;
$archiveDirectories = $this->storage->search($id);
foreach ($archiveDirectories as $directory) {
if ($directory->getPath() === $searchPath) {
if ($this->endsWith($directory->getPath(), $searchPath)) {
foreach ($directory->getDirectoryListing() as $archivedFile) {
error_log("mount: " . $archivedFile->getMountPoint()->getMountPoint() );
$member->addFile($archivedFile);
}
}
......@@ -75,6 +72,11 @@ class Club
return array();
}
private function endsWith( $str, $sub ) {
return ( substr( $str, strlen( $str ) - strlen( $sub ) ) == $sub );
}
private function openClubFile(string $club): File
{
$clubMemberFiles = $this->storage->search($club . self::MITGL_DAT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment