mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-24 12:17:05 -08:00
Updated Companies for #3059
This commit is contained in:
parent
6c8e9327c1
commit
c6ab34faee
|
@ -6,6 +6,7 @@ use Input;
|
|||
use Lang;
|
||||
use Redirect;
|
||||
use View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* This controller handles all actions related to Companies for
|
||||
|
@ -24,7 +25,7 @@ final class CompaniesController extends Controller
|
|||
* @since [v1.8]
|
||||
* @return View
|
||||
*/
|
||||
public function getIndex()
|
||||
public function index()
|
||||
{
|
||||
return View::make('companies/index')->with('companies', Company::all());
|
||||
}
|
||||
|
@ -36,7 +37,7 @@ final class CompaniesController extends Controller
|
|||
* @since [v1.8]
|
||||
* @return View
|
||||
*/
|
||||
public function getCreate()
|
||||
public function create()
|
||||
{
|
||||
return View::make('companies/edit')->with('item', new Company);
|
||||
}
|
||||
|
@ -48,14 +49,13 @@ final class CompaniesController extends Controller
|
|||
* @since [v1.8]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postCreate()
|
||||
public function store(Request $request)
|
||||
{
|
||||
$company = new Company;
|
||||
|
||||
$company->name = e(Input::get('name'));
|
||||
$company->name = e($request->input('name'));
|
||||
|
||||
if ($company->save()) {
|
||||
return redirect()->to('admin/settings/companies')
|
||||
return redirect()->route('companies.index')
|
||||
->with('success', trans('admin/companies/message.create.success'));
|
||||
} else {
|
||||
return redirect()->back()->withInput()->withErrors($company->getErrors());
|
||||
|
@ -72,10 +72,10 @@ final class CompaniesController extends Controller
|
|||
* @param int $companyId
|
||||
* @return View
|
||||
*/
|
||||
public function getEdit($companyId)
|
||||
public function edit($companyId)
|
||||
{
|
||||
if (is_null($item = Company::find($companyId))) {
|
||||
return redirect()->to('admin/settings/companies')
|
||||
return redirect()->route('companies.index')
|
||||
->with('error', trans('admin/companies/message.does_not_exist'));
|
||||
} else {
|
||||
return View::make('companies/edit')->with('item', $item);
|
||||
|
@ -90,20 +90,20 @@ final class CompaniesController extends Controller
|
|||
* @param int $companyId
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postEdit($companyId)
|
||||
public function update(Request $request, $companyId)
|
||||
{
|
||||
if (is_null($company = Company::find($companyId))) {
|
||||
return redirect()->to('admin/settings/companies')->with('error', trans('admin/companies/message.does_not_exist'));
|
||||
return redirect()->route('companies.index')->with('error', trans('admin/companies/message.does_not_exist'));
|
||||
} else {
|
||||
|
||||
|
||||
$company->name = e(Input::get('name'));
|
||||
$company->name = e($request->input('name'));
|
||||
|
||||
if ($company->save()) {
|
||||
return redirect()->to('admin/settings/companies')
|
||||
return redirect()->route('companies.index')
|
||||
->with('success', trans('admin/companies/message.update.success'));
|
||||
} else {
|
||||
return redirect()->to("admin/settings/companies/$companyId/edit")
|
||||
return redirect()->route('companies.edit', ['company' => $companyId])
|
||||
->with('error', trans('admin/companies/message.update.error'));
|
||||
}
|
||||
|
||||
|
@ -118,15 +118,15 @@ final class CompaniesController extends Controller
|
|||
* @param int $companyId
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postDelete($companyId)
|
||||
public function destroy($companyId)
|
||||
{
|
||||
if (is_null($company = Company::find($companyId))) {
|
||||
return redirect()->to('admin/settings/companies')
|
||||
return redirect()->route('companies.index')
|
||||
->with('error', trans('admin/companies/message.not_found'));
|
||||
} else {
|
||||
try {
|
||||
$company->delete();
|
||||
return redirect()->to('admin/settings/companies')
|
||||
return redirect()->route('companies.index')
|
||||
->with('success', trans('admin/companies/message.delete.success'));
|
||||
} catch (\Illuminate\Database\QueryException $exception) {
|
||||
/*
|
||||
|
@ -134,7 +134,7 @@ final class CompaniesController extends Controller
|
|||
* For example when rows in other tables are referencing this company
|
||||
*/
|
||||
if ($exception->getCode() == 23000) {
|
||||
return redirect()->to('admin/settings/companies')
|
||||
return redirect()->route('companies.index')
|
||||
->with('error', trans('admin/companies/message.assoc_users'));
|
||||
} else {
|
||||
throw $exception;
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
'createText' => trans('admin/companies/table.create') ,
|
||||
'updateText' => trans('admin/companies/table.update'),
|
||||
'helpTitle' => trans('admin/companies/general.about_companies_title'),
|
||||
'helpText' => trans('admin/companies/general.about_companies_text')
|
||||
'helpText' => trans('admin/companies/general.about_companies_text'),
|
||||
'formAction' => ($item) ? route('companies.update', ['company' => $item->id]) : route('companies.store'),
|
||||
])
|
||||
|
||||
{{-- Page content --}}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
@stop
|
||||
|
||||
@section('header_right')
|
||||
<a href="{{ route('create/company') }}" class="btn btn-primary pull-right">
|
||||
<a href="{{ route('companies.create') }}" class="btn btn-primary pull-right">
|
||||
{{ trans('general.create') }}</a>
|
||||
@stop
|
||||
|
||||
|
@ -32,11 +32,11 @@
|
|||
<td>{{ $company->id }}</td>
|
||||
<td>{{ $company->name }}</td>
|
||||
<td>
|
||||
<form method="POST" action="{{ route('delete/company', $company->id) }}" role="form">
|
||||
<form method="POST" action="{{ route('companies.destroy', $company->id) }}" role="form">
|
||||
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
|
||||
|
||||
<a href="{{ route('update/company', $company->id) }}" class="btn btn-sm btn-warning"
|
||||
<a href="{{ route('companies.edit', $company->id) }}" class="btn btn-sm btn-warning"
|
||||
title="{{ trans('button.edit') }}">
|
||||
<i class="fa fa-pencil icon-white"></i>
|
||||
</a>
|
||||
|
|
|
@ -317,7 +317,7 @@
|
|||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li {!! (Request::is('settings/companies*') ? ' class="active"' : '') !!}>
|
||||
<a href="{{ URL::to('admin/settings/companies') }}">
|
||||
<a href="{{ route('companies.index') }}">
|
||||
<i class="fa fa-building-o fa-fw"></i> @lang('general.companies')
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -13,6 +13,10 @@ Route::resource('fields', 'CustomFieldsController', [
|
|||
'parameters' => ['customfield' => 'field_id', 'fieldset' => 'fieldset_id']
|
||||
]);
|
||||
|
||||
Route::resource('companies', 'CompaniesController', [
|
||||
'parameters' => ['company' => 'company_id']
|
||||
]);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -141,17 +145,6 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function ()
|
|||
Route::get('/', [ 'as' => 'settings/backups', 'uses' => 'SettingsController@getBackups' ]);
|
||||
});
|
||||
|
||||
# Companies
|
||||
Route::group([ 'prefix' => 'companies' ], function () {
|
||||
|
||||
Route::get('{companyId}/edit', ['as' => 'update/company', 'uses' => 'CompaniesController@getEdit']);
|
||||
Route::get('create', ['as' => 'create/company', 'uses' => 'CompaniesController@getCreate']);
|
||||
Route::get('/', ['as' => 'companies', 'uses' => 'CompaniesController@getIndex']);
|
||||
|
||||
Route::post('{companyId}/delete', ['as' => 'delete/company', 'uses' => 'CompaniesController@postDelete']);
|
||||
Route::post('{companyId}/edit', 'CompaniesController@postEdit');
|
||||
Route::post('create', 'CompaniesController@postCreate');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class CompaniesCest
|
|||
{
|
||||
$I->wantTo('Test Company Creation');
|
||||
$I->lookForwardTo('seeing it load without errors');
|
||||
$I->amOnPage(route('create/company'));
|
||||
$I->amOnPage(route('companies.create'));
|
||||
$I->seeInTitle('Create Company');
|
||||
$I->see('Create Company', 'h1.pull-left');
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class CompaniesCest
|
|||
public function failsEmptyValidation(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo("Test Validation Fails with blank elements");
|
||||
$I->amOnPage(route('create/company'));
|
||||
$I->amOnPage(route('companies.create'));
|
||||
$I->click('Save');
|
||||
$I->seeElement('.alert-danger');
|
||||
$I->see('The name field is required.', '.alert-msg');
|
||||
|
@ -37,7 +37,7 @@ class CompaniesCest
|
|||
'name' => $company->name
|
||||
];
|
||||
$I->wantTo("Test Validation Succeeds");
|
||||
$I->amOnPage(route('create/company'));
|
||||
$I->amOnPage(route('companies.create'));
|
||||
$I->fillField('name', 'TestCompany');
|
||||
$I->submitForm('form#create-form', $values);
|
||||
$I->seeRecord('companies', $values);
|
||||
|
|
Loading…
Reference in a new issue