Skip to content

Commit

Permalink
Manage environmental variables.
Browse files Browse the repository at this point in the history
Addresses #133 and #108
  • Loading branch information
REBELinBLUE committed Jan 8, 2016
1 parent 6e78e4f commit f8d8c44
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 3 deletions.
56 changes: 56 additions & 0 deletions app/Http/Controllers/Resources/VariableController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace REBELinBLUE\Deployer\Http\Controllers\Resources;

use Illuminate\Support\Facades\Input;
use REBELinBLUE\Deployer\Http\Requests;
use REBELinBLUE\Deployer\Http\Requests\StoreVariableRequest;
use REBELinBLUE\Deployer\Repositories\Contracts\VariableRepositoryInterface;

/**
* Variable management controller.
*/
class VariableController extends ResourceController
{
/**
* Class constructor.
*
* @param VariableRepositoryInterface $repository
* @return void
*/
public function __construct(VariableRepositoryInterface $repository)
{
$this->repository = $repository;
}

/**
* Store a newly created variable in storage.
*
* @param StoreVariableRequest $request
* @return Response
*/
public function store(StoreVariableRequest $request)
{
return $this->repository->create($request->only(
'name',
'value',
'project_id'
));
}

/**
* Update the specified variable in storage.
*
* @param int $variable_id
* @param StoreVariableRequest $request
* @return Response
*/
public function update($variable_id, StoreVariableRequest $request)
{
return $this->repository->updateById($request->only(
'name',
'value',
'project_id'
), $variable_id);
}
}
25 changes: 25 additions & 0 deletions app/Http/Requests/StoreVariableRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace REBELinBLUE\Deployer\Http\Requests;

use REBELinBLUE\Deployer\Http\Requests\Request;

/**
* Request for validating variables.
*/
class StoreVariableRequest extends Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|max:255',
'value' => 'required',
'project_id' => 'required|integer|exists:projects,id',
];
}
}
1 change: 1 addition & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
];

Route::resource('servers', 'ServerController', $actions);
Route::resource('variables', 'VariableController', $actions);
Route::resource('commands', 'CommandController', $actions);
Route::resource('heartbeats', 'HeartbeatController', $actions);
Route::resource('notifications', 'NotificationController', $actions);
Expand Down
1 change: 1 addition & 0 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function register()
$this->bindInterface('SharedFile');
$this->bindInterface('Template');
$this->bindInterface('User');
$this->bindInterface('Variable');
}

/**
Expand Down
11 changes: 11 additions & 0 deletions app/Repositories/Contracts/VariableRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace REBELinBLUE\Deployer\Repositories\Contracts;

interface VariableRepositoryInterface
{
public function getAll();
public function create(array $fields);
public function updateById(array $fields, $model_id);
public function deleteById($model_id);
}
24 changes: 24 additions & 0 deletions app/Repositories/EloquentVariableRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace REBELinBLUE\Deployer\Repositories;

use REBELinBLUE\Deployer\Variable;
use REBELinBLUE\Deployer\Repositories\Contracts\VariableRepositoryInterface;
use REBELinBLUE\Deployer\Repositories\EloquentRepository;

/**
* The variable repository.
*/
class EloquentVariableRepository extends EloquentRepository implements VariableRepositoryInterface
{
/**
* Class constructor.
*
* @param Variable $model
* @return EloquentVariableRepository
*/
public function __construct(Variable $model)
{
$this->model = $model;
}
}
6 changes: 3 additions & 3 deletions resources/assets/js/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ var app = app || {};
}

variable.save({
name: $('#variable_name').val(),
value: $('#variable_value').val(),
name: $('#variable_name').val()
name: $('#variable_name').val(),
value: $('#variable_value').val(),
project_id: $('input[name="project_id"]').val(),
}, {
wait: true,
success: function(model, response, options) {
Expand Down

0 comments on commit f8d8c44

Please sign in to comment.