-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display image files #126
base: develop
Are you sure you want to change the base?
Display image files #126
Changes from all commits
9a656fc
f08ed61
39ca82f
a6c5bd4
6da5ada
b05a0a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ public function execute($request) | |
->select(array('Id', 'Filename')) | ||
->filterByBranchId($this->file->getBranchId()) | ||
->filterByFilename($this->file->getFilename(), Criteria::LESS_THAN) | ||
->filterByIsBinary(false) | ||
->orderByFilename(Criteria::DESC) | ||
->find() | ||
; | ||
|
@@ -44,12 +43,10 @@ public function execute($request) | |
->select(array('Id', 'Filename')) | ||
->filterByBranchId($this->file->getBranchId()) | ||
->filterByFilename($this->file->getFilename(), Criteria::GREATER_THAN) | ||
->filterByIsBinary(false) | ||
->orderByFilename(Criteria::ASC) | ||
->find() | ||
; | ||
|
||
|
||
$commitFrom = $request->getParameter('from', $this->branch->getCommitReference()); | ||
$commitTo = $request->getParameter('to', $this->branch->getLastCommit()); | ||
$this->commit_from = null; | ||
|
@@ -77,28 +74,53 @@ public function execute($request) | |
$this->previousFileId = $this->findClosestFileId($previousFiles, $modifiedFiles); | ||
$this->nextFileId = $this->findClosestFileId($nextFiles, $modifiedFiles); | ||
|
||
$this->fileContentLines = $this->gitCommand->getShowFileFromBranch( | ||
$this->repository->getGitDir(), | ||
$commitFrom, | ||
$commitTo, | ||
$this->file->getFilename(), | ||
$options | ||
); | ||
if ($this->file->getIsBinary()) | ||
{ | ||
$oldBinaryContent = $this->gitCommand->getShowFile( | ||
$this->repository->getGitDir(), | ||
$commitFrom, | ||
$this->file->getFilename() | ||
); | ||
|
||
$fileLineCommentsModel = CommentQuery::create() | ||
->filterByFileId($this->file->getId()) | ||
->filterByCommit($this->file->getLastChangeCommit()) | ||
->filterByType(CommentPeer::TYPE_LINE) | ||
->find() | ||
; | ||
$this->oldImageExists = !(strpos($oldBinaryContent, 'fatal: Path') === 0); | ||
$this->oldImageType = ImageUtils::getImageTypeFromContent($oldBinaryContent); | ||
$this->oldImageContent = base64_encode($oldBinaryContent); | ||
|
||
$this->userId = $this->getUser()->getId(); | ||
$newBinaryContent = $this->gitCommand->getShowFile( | ||
$this->repository->getGitDir(), | ||
$commitTo, | ||
$this->file->getFilename() | ||
); | ||
|
||
$this->fileLineComments = array(); | ||
foreach ($fileLineCommentsModel as $fileLineCommentModel) | ||
$this->newImageExists = !(strpos($newBinaryContent, 'fatal: Path') === 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. factorisation avec le bloc du dessus ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ça ne devrait pas être au getShowFile de faire ce test ? (pour ne pas vérifier la présence de cette chaine dans l'action). |
||
$this->newImageType = ImageUtils::getImageTypeFromContent($newBinaryContent); | ||
$this->newImageContent = base64_encode($newBinaryContent); | ||
} | ||
else | ||
{ | ||
$this->fileLineComments[$fileLineCommentModel->getPosition()][] = $fileLineCommentModel; | ||
$this->fileContentLines = $this->gitCommand->getShowFileFromBranch( | ||
$this->repository->getGitDir(), | ||
$commitFrom, | ||
$commitTo, | ||
$this->file->getFilename(), | ||
$options | ||
); | ||
|
||
$fileLineCommentsModel = CommentQuery::create() | ||
->filterByFileId($this->file->getId()) | ||
->filterByCommit($this->file->getLastChangeCommit()) | ||
->filterByType(CommentPeer::TYPE_LINE) | ||
->find() | ||
; | ||
|
||
$this->fileLineComments = array(); | ||
foreach ($fileLineCommentsModel as $fileLineCommentModel) | ||
{ | ||
$this->fileLineComments[$fileLineCommentModel->getPosition()][] = $fileLineCommentModel; | ||
} | ||
} | ||
|
||
$this->userId = $this->getUser()->getId(); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
class ImageUtils | ||
{ | ||
static public function getImageTypeFromContent($binaryContent) | ||
{ | ||
$supportedTypes = array( | ||
'jpeg' => "\xFF\xD8\xFF", | ||
'gif' => 'GIF', | ||
'png' => "\x89\x50\x4e\x47\x0d\x0a", | ||
'bmp' => 'BM', | ||
); | ||
|
||
foreach ($supportedTypes as $supportedType => $header) | ||
{ | ||
if (strpos($binaryContent, $header) === 0) | ||
{ | ||
return $supportedType; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,4 +80,15 @@ | |
} | ||
} | ||
} | ||
|
||
.imageDiff { | ||
float: left; | ||
margin: 20px; | ||
width: 46%; | ||
|
||
img { | ||
border: 1px solid #f9a; | ||
max-width: 100%; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,10 @@ | |
color: #4a3; | ||
font-size: 21px; | ||
margin-right: 3px; | ||
|
||
&.binary { | ||
color: @lightGrey; | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialiser ces paramètres ? pour toujours les avoir même quand on ne passe (même si dans la template on semble passer par une condition équivalente sur getIsBinary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
et puis, c'est pas un peu triché cette detection par rapport au message git pour déterminer si le fichier est nouveau :o ?