Skip to content

Commit c504073

Browse files
committed
Bunch of improvements and fixes
1 parent 2cf55e5 commit c504073

File tree

8 files changed

+100
-33
lines changed

8 files changed

+100
-33
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "darryldecode/laravelbackend",
33
"description": "Laravel 5 Backend",
4-
"keywords": ["laravel", "backend", "administrator", "dashboard"],
4+
"keywords": ["laravel", "laravel admin package", "backend", "administrator", "dashboard", "admin"],
55
"license": "MIT",
66
"authors": [
77
{

src/Darryldecode/Backend/Components/ContentBuilder/Views/customFields.blade.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
<div class="col-lg-5 col-md-5 custom-field-left">
5858
<h5 class="drawer-title-secondary"><i class="fa fa-info-circle"></i> FORM DETAILS:</h5>
5959
<div class="form-group">
60-
<label>Name:</label>
60+
<label>Form Display Name:</label>
6161
<input data-ng-model="fieldGroup.name" type="text" class="form-control">
6262
</div>
6363
<div class="form-group">
64-
<label>Form Name:</label>
64+
<label>Form Name-Key: <small><i>(This should be unique. You will not be able to change this after.)</i></small></label>
6565
<input data-ng-model="fieldGroup.formName" type="text" class="form-control">
6666
</div>
6767
<div class="form-group">
@@ -111,12 +111,12 @@
111111
<div class="col-lg-5 col-md-5 custom-field-left">
112112
<h5 class="drawer-title-secondary"><i class="fa fa-info-circle"></i> FORM DETAILS:</h5>
113113
<div class="form-group">
114-
<label>Name:</label>
114+
<label>Form Display Name:</label>
115115
<input data-ng-model="fieldGroup.name" type="text" class="form-control">
116116
</div>
117117
<div class="form-group">
118-
<label>Form Name:</label>
119-
<input data-ng-model="fieldGroup.formName" type="text" class="form-control">
118+
<label>Form Name-Key:</label>
119+
<input disabled="disabled" value="@{{::fieldGroup.formName}}" type="text" class="form-control">
120120
</div>
121121
<div class="form-group">
122122
<label>Form For:</label>

src/Darryldecode/Backend/Components/MediaManager/Commands/UploadCommand.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ public function handle(Repository $config,Image $image)
6060
// upload files
6161
foreach($this->files as $file)
6262
{
63+
// normalize file name
64+
$normalizedFileName = $this->normalizeFileName($file->getClientOriginalName());
65+
6366
// save the file
6467
$file->move(
6568
$config->get('filesystems.disks.local.root').'/'.$this->normalizePath($path),
66-
$file->getClientOriginalName()
69+
$normalizedFileName
6770
);
6871

69-
$filePath = $config->get('filesystems.disks.local.root').'/'.$this->normalizePath($path).'/'.$file->getClientOriginalName();
72+
$filePath = $config->get('filesystems.disks.local.root').'/'.$this->normalizePath($path).'/'.$normalizedFileName;
7073
$file_name = pathinfo($filePath, PATHINFO_FILENAME);
7174
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
7275

@@ -117,4 +120,15 @@ protected function produceThumbFileName($file_name, $file_size_name, $file_exten
117120
{
118121
return $file_name.'_'.$file_size_name.'.'.$file_extension;
119122
}
123+
124+
/**
125+
* when uploading a file, we will remove dashes because dashes are use in UI as size convention
126+
*
127+
* @param $string
128+
* @return mixed
129+
*/
130+
protected function normalizeFileName($string)
131+
{
132+
return str_replace('_','',$string);
133+
}
120134
}

src/Darryldecode/Backend/Components/User/Models/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Group extends BaseModel {
4444
*/
4545
public static $rules = array(
4646
'name' => 'required',
47-
'permissions' => 'required|array',
47+
'permissions' => 'array',
4848
);
4949

5050
/**

src/Darryldecode/Backend/Public/backend/cb/app/contents/modals/controller.gallery.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,29 @@ angular.module('cb.content').controller('GalleryModalController', ['$scope','$ti
6868

6969
// just a helper on view
7070
$scope.getLastSegment = function (path) {
71-
return path.split('/').pop();
71+
72+
var separators = ["/","\\\\"];
73+
74+
return path.split(new RegExp(separators.join('|'), 'g')).pop();
7275
};
7376

7477
// get size name. Eg. ( name_large.jpg -> large )
7578
$scope.getSizeName = function(path) {
7679
var sizeName = 'Original';
7780
var fileName = $scope.getLastSegment(path);
78-
var f = fileName.split('_');
79-
if(f.length >= 2) {
80-
sizeName = f[1].split('.')[0];
81+
82+
if( isImage(fileName) ) {
83+
var f = fileName.split('_');
84+
if(f.length >= 2) {
85+
sizeName = f[f.length - 1].split('.')[0];
86+
}
8187
}
88+
8289
return sizeName;
90+
91+
function isImage(src) {
92+
return (/(.*)\.(?:jpe?g|gif|png)$/i).test(src);
93+
}
8394
};
8495

8596
// uploads the files

src/Darryldecode/Backend/Public/backend/cb/app/media-manager/controller.manage.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,31 @@ angular.module('cb.mediaManager').controller('MediaManagerController', ['$scope'
148148
upload($scope.uploader.files, {path: $scope.mediaManager.currentPath});
149149
});
150150

151-
// just a helper on view
151+
// just a helper on view Eg. ( some_folder/another/file.txt -> file.txt )
152152
$scope.getLastSegment = function (path) {
153-
return path.split('/').pop();
153+
154+
var separators = ["/","\\\\"];
155+
156+
return path.split(new RegExp(separators.join('|'), 'g')).pop();
154157
};
155158

156159
// get size name. Eg. ( name_large.jpg -> large )
157160
$scope.getSizeName = function(path) {
158161
var sizeName = 'Original';
159162
var fileName = $scope.getLastSegment(path);
160-
var f = fileName.split('_');
161-
if(f.length >= 2) {
162-
sizeName = f[1].split('.')[0];
163+
164+
if( isImage(fileName) ) {
165+
var f = fileName.split('_');
166+
if(f.length >= 2) {
167+
sizeName = f[f.length - 1].split('.')[0];
168+
}
163169
}
170+
164171
return sizeName;
172+
173+
function isImage(src) {
174+
return (/(.*)\.(?:jpe?g|gif|png)$/i).test(src);
175+
}
165176
};
166177

167178
// upload

src/Darryldecode/Backend/Public/backend/cb/app/media-manager/modals/rename.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<div class="modal-header">
22
ENTER NEW NAME:
3+
<div class="alert alert-warning">
4+
<small><i class="fa fa-warning"></i> When renaming an image, please retain the "_size.jpg". Eg. (myfile_large.jpg rename to: myNewName_large.jpg)</small>
5+
</div>
36
</div>
47
<div class="modal-body">
58
<input data-ng-model="newName" type="text" class="form-control">

tests/User/functional/commands/CreateGroupCommandTest.php

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testCreateGroupShouldDenyIfUserPerformingActionIsNotSuperUser()
6969
$this->assertEquals('Not enough permission.', $result->getMessage());
7070
}
7171

72-
public function testRequiredFields()
72+
public function testRequiredNameField()
7373
{
7474
// create user and logged in (the user who will perform the action)
7575
$user = User::create(array(
@@ -98,24 +98,22 @@ public function testRequiredFields()
9898
$this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
9999
$this->assertEquals(400, $result->getStatusCode(), 'Status code should be 400.');
100100
$this->assertEquals('The name field is required.', $result->getMessage());
101+
}
101102

102-
// dummy request | name permissions field should be required
103-
$request = Request::create('','POST',array(
104-
'name' => 'moderator',
105-
'permissions' => '',
103+
public function testPermissionsFieldShouldBeAnArray()
104+
{
105+
// create user and logged in (the user who will perform the action)
106+
$user = User::create(array(
107+
'first_name' => 'darryl',
108+
'email' => '[email protected]',
109+
'password' => 'pass$darryl',
110+
'permissions' => array(
111+
'superuser' => 1
112+
)
106113
));
107114

108-
// begin
109-
$result = $this->commandDispatcher->dispatchFrom(
110-
'Darryldecode\Backend\Components\User\Commands\CreateGroupCommand',
111-
$request
112-
);
113-
114-
$this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
115-
$this->assertEquals(400, $result->getStatusCode(), 'Status code should be 400.');
116-
$this->assertEquals('The permissions field is required.', $result->getMessage());
115+
$this->application['auth']->loginUsingId($user->id);
117116

118-
// dummy request | name permissions field should be an array
119117
$request = Request::create('','POST',array(
120118
'name' => 'moderator',
121119
'permissions' => 'Not an array',
@@ -174,4 +172,34 @@ public function testCreateShouldCreateGroupWhenAllCheckPointsPassed()
174172
$this->assertArrayHasKey('forum.create',$group->permissions);
175173
$this->assertArrayHasKey('forum.delete',$group->permissions);
176174
}
175+
176+
public function testShouldCreateGroupEvenWithoutPermissionsYet()
177+
{
178+
// create user and logged in (the user who will perform the action)
179+
$user = User::create(array(
180+
'first_name' => 'darryl',
181+
'email' => '[email protected]',
182+
'password' => 'pass$darryl',
183+
'permissions' => array(
184+
'superuser' => 1
185+
)
186+
));
187+
188+
$this->application['auth']->loginUsingId($user->id);
189+
190+
$request = Request::create('','POST',array(
191+
'name' => 'moderator',
192+
'permissions' => array(),
193+
));
194+
195+
// begin
196+
$result = $this->commandDispatcher->dispatchFrom(
197+
'Darryldecode\Backend\Components\User\Commands\CreateGroupCommand',
198+
$request
199+
);
200+
201+
$this->assertTrue($result->isSuccessful(), 'Transaction should be successful.');
202+
$this->assertEquals(201, $result->getStatusCode(), 'Status code should be 400.');
203+
$this->assertEquals('Group successfully created.', $result->getMessage());
204+
}
177205
}

0 commit comments

Comments
 (0)