Skip to content

Commit

Permalink
Minor Changes
Browse files Browse the repository at this point in the history
  - minor ProjectAction refactoring
  - removed "duplicated" command
  - fixes visibility toggler
  - my profile minor design fixes + remove second mail
  - fix old code view image loading (fileName is no xml attribute in new catrobat version!)
  • Loading branch information
dmetzner committed Jun 10, 2020
1 parent 027e511 commit 601e946
Show file tree
Hide file tree
Showing 23 changed files with 183 additions and 272 deletions.
9 changes: 9 additions & 0 deletions assets/css/base/_icons.scss
Expand Up @@ -80,4 +80,13 @@

#help-button {
cursor:pointer
}

.text-icon-aligned {
display: flex;
align-items: center;
}

.trailing-icon {
margin-left: auto;
}
20 changes: 4 additions & 16 deletions assets/css/custom/login.scss
Expand Up @@ -98,23 +98,7 @@ input:valid ~ label {
width: 50%;
}

.group-with-icon-wrapper {
overflow: hidden;
}

.group-with-icon {
width: 90%;
float: left;
}

.icon-from-group {
float: right;
width: 10%;
text-align: center;
font-size: 1.5em;
margin-top: 1em;
padding-top: 0.1em;
}

/* HIGHLIGHTER ================================== */

Expand Down Expand Up @@ -229,3 +213,7 @@ hr {
.align_start {
text-align: start;
}

.show-hide-password {
display: flex;
}
1 change: 0 additions & 1 deletion assets/css/custom/profile.scss
Expand Up @@ -32,7 +32,6 @@
}

.profile-data {
padding: 0.5em;
word-break: break-word;
}

Expand Down
8 changes: 4 additions & 4 deletions assets/js/custom/MyProfile.js
Expand Up @@ -47,9 +47,10 @@ const MyProfile = function (profileUrl, saveUsername,
const emailData = $('#email-wrapper > .profile-data')
const countryEditContainer = $('#country-edit-container')
const countryData = $('#country-wrapper > .profile-data')
const passwordData = $('#password-wrapper > .profile-data')
const accountSettingsContainer = $('#account-settings-container')
const profileSections = [
[passwordEditContainer, null],
[passwordEditContainer, passwordData],
[emailEditContainer, emailData], [countryEditContainer, countryData],
[accountSettingsContainer, null]
]
Expand All @@ -59,7 +60,7 @@ const MyProfile = function (profileUrl, saveUsername,
})

$('#edit-password-button').on('click', function () {
toggleEditSection(passwordEditContainer)
toggleEditSection(passwordEditContainer, passwordData)
})

$('#edit-email-button').on('click', function () {
Expand Down Expand Up @@ -227,10 +228,9 @@ const MyProfile = function (profileUrl, saveUsername,
$('.error-message').addClass('d-none')

const newEmail = email.val()
const additionalEmail = $('#additional-email').val()
$.post(self.saveEmailUrl, {
firstEmail: newEmail,
secondEmail: additionalEmail
secondEmail: ''
}, function (data) {
switch (parseInt(data.statusCode)) {
case statusCodeOk:
Expand Down
9 changes: 3 additions & 6 deletions assets/js/custom/PasswordVisibilityToggler.js
Expand Up @@ -2,20 +2,17 @@

// eslint-disable-next-line no-unused-vars
$(document).ready(function () {
const toggleButton = $('.show-hide-password a')
const toggleButtonIcon = $('.show-hide-password i')
const toggleButton = $('.show-hide-password .pw-toggler')
const passwordField = $('.show-hide-password input')

toggleButton.on('click', function (event) {
event.preventDefault()
if (passwordField.attr('type') === 'text') {
passwordField.attr('type', 'password')
toggleButtonIcon.addClass('fa-eye-slash')
toggleButtonIcon.removeClass('fa-eye')
$(this).text('visibility')
} else if (passwordField.attr('type') === 'password') {
passwordField.attr('type', 'text')
toggleButtonIcon.removeClass('fa-eye-slash')
toggleButtonIcon.addClass('fa-eye')
$(this).text('visibility_off')
}
})
})
1 change: 1 addition & 0 deletions src/Catrobat/Controller/Admin/MaintainController.php
Expand Up @@ -31,6 +31,7 @@ public function extractedAction(KernelInterface $kernel): RedirectResponse

$input = new ArrayInput([
'command' => 'catrobat:clean:extracted',
'--remove-all' => true,
]);

$return = $application->run($input, new NullOutput());
Expand Down
40 changes: 8 additions & 32 deletions src/Catrobat/Controller/Web/ProgramController.php
Expand Up @@ -149,15 +149,12 @@ public function projectAction(Request $request, string $id): Response

/** @var User|null $user */
$user = $this->getUser();
$logged_in = false;
$logged_in = null !== $user;
$my_program = $logged_in && $project->getUser() === $user;

$active_user_like_types = [];
$user_name = null;

if (null !== $user)
if ($logged_in)
{
$logged_in = true;
$user_name = $user->getUsername();
$likes = $this->program_manager->findUserLikes($project->getId(), $user->getId());
foreach ($likes as $like)
{
Expand All @@ -173,41 +170,20 @@ public function projectAction(Request $request, string $id): Response
$referrer, $program_comments, $request
);

$user_programs = $this->findUserPrograms($user, $project);

$isReportedByUser = $this->checkReportedByUser($project, $user);

$program_url = $this->generateUrl('program',
['id' => $project->getId()], UrlGeneratorInterface::ABSOLUTE_PATH);

$share_text = trim($project->getName().' on '.$program_url.' '.
$project->getDescription());

$jam = $this->extractGameJamConfig();

$max_description_size = $this->getParameter('catrobat.max_description_upload_size');

$my_program = false;
if ($user_programs && count($user_programs) > 0)
{
$my_program = true;
}

$this->extracted_file_repository->loadProgramExtractedFile($project);
// Catblocks is working with the extracted files not the project zip.
$this->extracted_file_repository->ensureProjectIsExtracted($project);

return $this->render('Program/program.html.twig', [
'program_details_url_template' => $router->generate('program', ['id' => 0]),
'program' => $project,
'program_details' => $program_details,
'my_program' => $my_program,
'already_reported' => $isReportedByUser,
'shareText' => $share_text,
'program_url' => $program_url,
'jam' => $jam,
'user_name' => $user_name,
'max_description_size' => $max_description_size,
'logged_in' => $logged_in,
'max_description_size' => $this->getParameter('catrobat.max_description_upload_size'),
'extracted_path' => $this->parameter_bag->get('catrobat.file.extract.path'),
'jam' => $jam,
]);
}

Expand Down Expand Up @@ -692,7 +668,7 @@ private function createProgramDetailsArray(Program $program,
'comments' => $program_comments,
'commentsLength' => count($program_comments),
'commentsAvatars' => $comments_avatars,
'remixesLength' => $this->remix_manager->remixCount($program->getId()),
'remixesLength' => $this->remix_manager->remixCount($program->getId()), // Huge performance killer!
'activeLikeTypes' => $active_like_types,
'activeUserLikeTypes' => $active_user_like_types,
'totalLikeCount' => $total_like_count,
Expand Down
18 changes: 15 additions & 3 deletions src/Catrobat/Services/CatrobatCodeParser/ParsedObjectAsset.php
Expand Up @@ -8,15 +8,15 @@ class ParsedObjectAsset
{
protected SimpleXMLElement $asset_xml_properties;

protected ?string $name;
protected ?string $name = null;

protected ?string $file_name;
protected ?string $file_name = null;

public function __construct(SimpleXMLElement $asset_xml_properties)
{
$this->asset_xml_properties = $asset_xml_properties;
$this->name = $asset_xml_properties[Constants::NAME_ATTRIBUTE];
$this->file_name = rawurlencode($asset_xml_properties['fileName']);
$this->file_name = $this->extractFileName($asset_xml_properties);
}

public function getName(): ?string
Expand All @@ -28,4 +28,16 @@ public function getFileName(): ?string
{
return $this->file_name;
}

private function extractFileName(SimpleXMLElement $asset_xml_properties): string
{
// different catrobat versions: fileName is either in the attributes (old) or a separate member (new)
$file_name = $asset_xml_properties['fileName'];
if ('' === $this->file_name)
{
$file_name = $asset_xml_properties->fileName;
}

return rawurlencode($file_name);
}
}
35 changes: 29 additions & 6 deletions src/Catrobat/Services/ExtractedFileRepository.php
Expand Up @@ -48,6 +48,24 @@ public function __construct(ParameterBagInterface $parameter_bag, CatrobatFileEx
$this->logger = $logger;
}

public function ensureProjectIsExtracted(Program $project): bool
{
try
{
$hash = $project->getExtractedDirectoryHash();
if (null === $hash || !file_exists($this->local_path.$hash))
{
$this->extractProject($project);
}
}
catch (Exception $e)
{
return false;
}

return true;
}

public function loadProgramExtractedFile(Program $program): ?ExtractedCatrobatFile
{
try
Expand All @@ -64,12 +82,7 @@ public function loadProgramExtractedFile(Program $program): ?ExtractedCatrobatFi

try
{
$program_file = $this->program_file_repo->getProgramFile($program->getId());
$extracted_file = $this->file_extractor->extract($program_file);
$program->setExtractedDirectoryHash($extracted_file->getDirHash());
$this->program_manager->save($program);

return $extracted_file;
return $this->extractProject($program);
}
catch (Exception $e)
{
Expand Down Expand Up @@ -101,4 +114,14 @@ public function removeProgramExtractedFile(Program $program): void
);
}
}

private function extractProject(Program $program): ExtractedCatrobatFile
{
$program_file = $this->program_file_repo->getProgramFile($program->getId());
$extracted_file = $this->file_extractor->extract($program_file);
$program->setExtractedDirectoryHash($extracted_file->getDirHash());
$this->program_manager->save($program);

return $extracted_file;
}
}
57 changes: 0 additions & 57 deletions src/Commands/Maintenance/CleanExtractedFileCommand.php

This file was deleted.

@@ -1,6 +1,6 @@
<?php

namespace App\Commands\Reset;
namespace App\Commands\Maintenance;

use App\Catrobat\Services\ExtractedFileRepository;
use App\Entity\Program;
Expand All @@ -14,9 +14,12 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

class ClearExtractedProjects extends Command
/**
* Class CleanExtractedProjectsCommand.
*/
class CleanExtractedProjectsCommand extends Command
{
protected static $defaultName = 'catrobat:clear:extracted';
protected static $defaultName = 'catrobat:clean:extracted';

private ProgramManager $program_manager;

Expand Down Expand Up @@ -44,7 +47,7 @@ public function __construct(ProgramManager $program_manager,

protected function configure(): void
{
$this->setName('catrobat:clear:extracted')
$this->setName('catrobat:clean:extracted')
->setDescription('Removes all extracted project data that is not used anymore.')
->addOption('remove-all', '', InputOption::VALUE_NONE,
'All extracted data will be cleared. Project zips will be re-extracted when opening a project page.'
Expand Down
6 changes: 4 additions & 2 deletions templates/Program/programComments.html.twig
Expand Up @@ -45,13 +45,15 @@
<div class="date">
{{ comment.uploadDate.format('Y-m-d') }}
</div>
{% if comment.username != user_name %}
{% if not(app.user) or (app.user and comment.username != app.user.username) %}
{# Everybody, but the comment owner must be able to report a comment #}
<a id="comment-report-button-{{ comment.id }}" class="comment-report-button"
data-toggle="tooltip" title="{{ 'programs.report'|trans({}, 'catroweb') }}">
<i class="ml-3 fas fa-ban text-danger"></i>
</a>
{% endif %}
{% if program_details.isAdmin or comment.username == user_name %}
{% if program_details.isAdmin or (app.user and comment.username == app.user.username) %}
{# Only Admins and comment owner can delete the comment #}
<a id="comment-delete-button-{{ comment.id }}" class="comment-delete-button"
data-toggle="tooltip" title="{{ 'programs.delete'|trans({}, 'catroweb') }}">
<i class="ml-2 fas fa-trash-alt text-danger"></i>
Expand Down

0 comments on commit 601e946

Please sign in to comment.