Add laravel routes to javascript (#4092)

* Add laravel routes to javascript

This will clean up a lot of passing of urls.  Adds a route() helper and
everything...

This commit also moves the customfield fetching to only be fetched once
and shared with each file, rather than once for each file.

* Try to fix travis unit test things.

* Downgrade doctrine/inflector for php5

* Attempt to occasional seeder issues on travis if the asset does not generate validatable data.

* Update sql dump for functional tests.

* Try to fix api tests.
This commit is contained in:
Daniel Meltzer 2017-10-01 15:59:55 -04:00 committed by snipe
parent 23ca2d9a0b
commit c2616412c0
21 changed files with 137911 additions and 638 deletions

View file

@ -43,7 +43,7 @@ before_script:
# use the $DB env variable to determine the phpunit.xml to use # use the $DB env variable to determine the phpunit.xml to use
# script: ./vendor/bin/codecept run --env testing-ci # script: ./vendor/bin/codecept run --env testing-ci
script: script:
- ./vendor/bin/codecept run unit --env testing-ci - ./vendor/bin/codecept run unit
# - ./vendor/bin/codecept run acceptance --env=testing-ci # - ./vendor/bin/codecept run acceptance --env=testing-ci
- ./vendor/bin/codecept run functional --env=functional-travis - ./vendor/bin/codecept run functional --env=functional-travis
#script: ./vendor/bin/codecept run #script: ./vendor/bin/codecept run

View file

@ -29,7 +29,6 @@ class ImportsTransformer
'header_row' => $import->header_row, 'header_row' => $import->header_row,
'first_row' => $import->first_row, 'first_row' => $import->first_row,
'field_map' => $import->field_map, 'field_map' => $import->field_map,
'process_url'=> route('api.imports.importFile', $import->id),
]; ];
return $array; return $array;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,23 +1,8 @@
{ {
"/build/vue.js": "/build/vue.js",
"/mix.js": "/mix.js",
"/build/app.css": "/build/app.535d8af1016a2377e449920c617f0197.css",
"/build/AdminLTE.css": "/build/AdminLTE.3d8a2b2e33baa060b1b324363ad5e1c2.css",
"/build/overrides.css": "/build/overrides.617623c6a96be3e0cbd11c5d4039ec10.css",
"/css/all.css": "/css/all.css",
"/js/all.js": "/js/all.js",
"/css/app.css": "/css/app.css",
"/css/dist/all.css": "/css/dist/all.css",
"/js/dist/all.js": "/js/dist/all.js",
"/css/AdminLTE.css": "/css/AdminLTE.css",
"/css/overrides.css": "/css/overrides.css",
"/css/skin-blue.css": "/css/skin-blue.css",
"/vue.js": "/vue.js", "/vue.js": "/vue.js",
"/vue.js.map": "/vue.js.map", "/css/AdminLTE.css": "/css/AdminLTE.css",
"/mix.js.map": "/mix.js.map", "/css/app.css": "/css/app.css",
"/css/AdminLTE.css.map": "/css/AdminLTE.css.map", "/css/overrides.css": "/css/overrides.css",
"/css/app.css.map": "/css/app.css.map", "/public/css/dist/all.css": "/public/css/dist/all.css",
"/css/overrides.css.map": "/css/overrides.css.map", "/public/js/dist/all.js": "/public/js/dist/all.js"
"public/css/dist/all.css": "public/css/dist/all.css",
"public/js/dist/all.js": "public/js/dist/all.js"
} }

52884
build/vue.js

File diff suppressed because one or more lines are too long

View file

@ -11,6 +11,8 @@
"doctrine/cache": "^1.6", "doctrine/cache": "^1.6",
"doctrine/common": "^2.7", "doctrine/common": "^2.7",
"doctrine/dbal": "v2.5.13", "doctrine/dbal": "v2.5.13",
"doctrine/inflector": "1.1.*",
"doctrine/instantiator": "1.0.*",
"erusev/parsedown": "^1.6", "erusev/parsedown": "^1.6",
"fideloper/proxy": "^3.1", "fideloper/proxy": "^3.1",
"intervention/image": "^2.3", "intervention/image": "^2.3",
@ -27,10 +29,11 @@
"schuppo/password-strength": "~1.5", "schuppo/password-strength": "~1.5",
"spatie/laravel-backup": "^3.0.0", "spatie/laravel-backup": "^3.0.0",
"tecnickcom/tc-lib-barcode": "^1.15", "tecnickcom/tc-lib-barcode": "^1.15",
"tightenco/ziggy": "^0.4.1",
"unicodeveloper/laravel-password": "^1.0", "unicodeveloper/laravel-password": "^1.0",
"watson/validating": "^3.0", "watson/validating": "^3.0",
"doctrine/instantiator": "1.0.*", "phpspec/prophecy": "1.6.2",
"doctrine/inflector": "1.2.*" "phpdocumentor/reflection-docblock": "3.2.2"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "~1.4", "fzaninotto/faker": "~1.4",

1064
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -255,7 +255,7 @@ return [
Laravel\Tinker\TinkerServiceProvider::class, Laravel\Tinker\TinkerServiceProvider::class,
Unicodeveloper\DumbPassword\DumbPasswordServiceProvider::class, Unicodeveloper\DumbPassword\DumbPasswordServiceProvider::class,
Schuppo\PasswordStrength\PasswordStrengthServiceProvider::class, Schuppo\PasswordStrength\PasswordStrengthServiceProvider::class,
Tightenco\Ziggy\ZiggyServiceProvider::class, // Laravel routes in vue
/* /*
* Application Service Providers... * Application Service Providers...

View file

@ -19,12 +19,14 @@ $factory->defineAs(Actionlog::class, 'asset-checkout', function (Faker\Generator
$company = factory(App\Models\Company::class)->create(); $company = factory(App\Models\Company::class)->create();
$user = factory(App\Models\User::class)->create(['company_id' => $company->id]); $user = factory(App\Models\User::class)->create(['company_id' => $company->id]);
$target = factory(App\Models\User::class)->create(['company_id' => $company->id]); $target = factory(App\Models\User::class)->create(['company_id' => $company->id]);
// $item = factory(App\Models\Asset::class)->create(['company_id' => $company->id]); do {
$item = factory(App\Models\Asset::class)->create(['company_id' => $company->id]);
} while (!$item->isValid());
// dd($item); // dd($item);
return [ return [
'user_id' => $user->id, 'user_id' => $user->id,
'action_type' => 'checkout', 'action_type' => 'checkout',
'item_id' => factory(App\Models\Asset::class)->create(['company_id' => $company->id])->id, 'item_id' => $item->id,
'item_type' => App\Models\Asset::class, 'item_type' => App\Models\Asset::class,
'target_id' => $target->id, 'target_id' => $target->id,
'target_type' => get_class($target), 'target_type' => get_class($target),

12296
public/css/dist/all.css vendored

File diff suppressed because one or more lines are too long

61514
public/js/dist/all.js vendored

File diff suppressed because one or more lines are too long

View file

@ -67,7 +67,7 @@ tr {
<script> <script>
export default { export default {
props: ['file', 'customFieldUrl'], props: ['file', 'customFields'],
data() { data() {
return { return {
activeFile: this.file, activeFile: this.file,
@ -130,14 +130,13 @@ tr {
{id: 'jobtitle', text: 'Job Title' }, {id: 'jobtitle', text: 'Job Title' },
{id: 'phone_number', text: 'Phone Number' }, {id: 'phone_number', text: 'Phone Number' },
], ],
customFields: [], customFields: this.customFields,
}, },
columnMappings: this.file.field_map || {}, columnMappings: this.file.field_map || {},
activeColumn: null, activeColumn: null,
} }
}, },
created() { created() {
this.fetchCustomFields();
window.eventHub.$on('showDetails', this.toggleExtendedDisplay) window.eventHub.$on('showDetails', this.toggleExtendedDisplay)
this.populateSelect2ActiveItems(); this.populateSelect2ActiveItems();
}, },
@ -155,21 +154,9 @@ tr {
} }
}, },
methods: { methods: {
fetchCustomFields() {
this.$http.get(this.customFieldUrl)
.then( ({data}) => {
data = data.rows;
data.forEach((item) => {
this.columnOptions.customFields.push({
'id': item.db_column_name,
'text': item.name,
})
})
});
},
postSave() { postSave() {
this.statusText = "Processing..."; this.statusText = "Processing...";
this.$http.post(this.file.process_url, { this.$http.post(route('api.imports.importFile', this.file.id), {
'import-update': this.options.update, 'import-update': this.options.update,
'import-type': this.options.importType, 'import-type': this.options.importType,
'column-mappings': this.columnMappings 'column-mappings': this.columnMappings

View file

@ -11,8 +11,6 @@ th {
<script> <script>
require('blueimp-file-upload'); require('blueimp-file-upload');
export default { export default {
props: ['importUrl'],
/* /*
* The component's data. * The component's data.
*/ */
@ -32,13 +30,15 @@ th {
currentPercent: "0", currentPercent: "0",
statusText: '', statusText: '',
visible: false visible: false
} },
customFields: [],
}; };
}, },
mounted() { mounted() {
window.eventHub.$on('importErrors', this.updateImportErrors); window.eventHub.$on('importErrors', this.updateImportErrors);
this.fetchFiles(); this.fetchFiles();
this.fetchCustomFields();
let vm = this; let vm = this;
$('#fileupload').fileupload({ $('#fileupload').fileupload({
dataType: 'json', dataType: 'json',
@ -71,7 +71,7 @@ th {
methods: { methods: {
fetchFiles() { fetchFiles() {
this.$http.get(this.importUrl) this.$http.get(route('api.imports.index'))
.then( ({data}) => this.files = data, // Success .then( ({data}) => this.files = data, // Success
//Fail //Fail
(response) => { (response) => {
@ -80,8 +80,20 @@ th {
this.alert.message="Something went wrong fetching files..."; this.alert.message="Something went wrong fetching files...";
}); });
}, },
fetchCustomFields() {
this.$http.get(route('api.customfields.index'))
.then( ({data}) => {
data = data.rows;
data.forEach((item) => {
this.customFields.push({
'id': item.db_column_name,
'text': item.name,
})
})
});
},
deleteFile(file, key) { deleteFile(file, key) {
this.$http.delete(this.importUrl+"/"+file.id) this.$http.delete(route('api.imports.destroy', file.id))
.then((response) => this.files.splice(key, 1), // Success, remove file from array. .then((response) => this.files.splice(key, 1), // Success, remove file from array.
(response) => {// Fail (response) => {// Fail
this.alert.type="danger"; this.alert.type="danger";
@ -98,7 +110,7 @@ th {
}, },
updateImportErrors(errors) { updateImportErrors(errors) {
this.importErrors = errors; this.importErrors = errors;
} },
}, },
computed: { computed: {

View file

@ -16,7 +16,7 @@
{{-- Page content --}} {{-- Page content --}}
@section('content') @section('content')
<div id="app"> <div id="app">
<importer inline-template import-url="{{route('api.imports.index')}}" v-cloak> <importer inline-template v-cloak>
<div class="row"> <div class="row">
<alert v-show="alert.visible" :alert-type="alert.type" v-on:hide="alert.visible = false">@{{ alert.message }}</alert> <alert v-show="alert.visible" :alert-type="alert.type" v-on:hide="alert.visible = false">@{{ alert.message }}</alert>
<errors :errors="importErrors"></errors> <errors :errors="importErrors"></errors>
@ -65,7 +65,7 @@
<import-file <import-file
:key="currentFile.id" :key="currentFile.id"
:file="currentFile" :file="currentFile"
customFieldUrl="{{route('api.customfields.index')}}" :custom-fields="customFields"
@alert="updateAlert(alert)"> @alert="updateAlert(alert)">
</import-file> </import-file>
</template> </template>

View file

@ -31,8 +31,6 @@
window.Laravel = { csrfToken: '{{ csrf_token() }}' }; window.Laravel = { csrfToken: '{{ csrf_token() }}' };
</script> </script>
<style nonce="{{ csrf_token() }}"> <style nonce="{{ csrf_token() }}">
@if ($snipeSettings) @if ($snipeSettings)
@if ($snipeSettings->header_color) @if ($snipeSettings->header_color)
@ -68,8 +66,6 @@
} }
</style> </style>
<script nonce="{{ csrf_token() }}"> <script nonce="{{ csrf_token() }}">
window.snipeit = { window.snipeit = {
settings: { settings: {
@ -77,7 +73,8 @@
} }
}; };
</script> </script>
<!-- Add laravel route sinto javascript Primarily useful for vue.-->
@routes
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]> <!--[if lt IE 9]>

View file

@ -1,8 +1,8 @@
-- MySQL dump 10.13 Distrib 5.7.18, for Linux (x86_64) -- MySQL dump 10.13 Distrib 5.7.19, for Linux (x86_64)
-- --
-- Host: localhost Database: snipeittests -- Host: localhost Database: snipeittests
-- ------------------------------------------------------ -- ------------------------------------------------------
-- Server version 5.7.18-0ubuntu0.16.10.1 -- Server version 5.7.19-0ubuntu0.17.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@ -1347,7 +1347,7 @@ CREATE TABLE `users` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `users_activation_code_index` (`activation_code`), KEY `users_activation_code_index` (`activation_code`),
KEY `users_reset_password_code_index` (`reset_password_code`) KEY `users_reset_password_code_index` (`reset_password_code`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -1392,4 +1392,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-05-22 20:08:33 -- Dump completed on 2017-10-01 15:36:56

View file

@ -1,10 +1,16 @@
<?php <?php
namespace Helper; namespace Helper;
use Illuminate\Support\Facades\Artisan;
// here you can define custom actions // here you can define custom actions
// all public methods declared in helper class will be available in $I // all public methods declared in helper class will be available in $I
class Api extends \Codeception\Module class Api extends \Codeception\Module
{ {
public function setupDatabase()
{
Artisan::call('migrate');
Artisan::call('db:seed');
}
} }

View file

@ -11,3 +11,4 @@ modules:
environment_file: .env.testing environment_file: .env.testing
disable_middleware: true disable_middleware: true
cleanup: true cleanup: true

View file

@ -9,15 +9,16 @@ class ApiAssetsCest
public function _before(ApiTester $I) public function _before(ApiTester $I)
{ {
$I->setupDatabase();
$this->faker = \Faker\Factory::create(); $this->faker = \Faker\Factory::create();
$this->user = \App\Models\User::find(1); $this->user = \App\Models\User::find(1);
$I->amBearerAuthenticated($I->getToken($this->user)); $I->amBearerAuthenticated($I->getToken($this->user));
} }
/** @test */ /** @test */
public function indexAssets(ApiTester $I) public function indexAssets(ApiTester $I)
{ {
$I->wantTo('Get a list of assets'); $I->wantTo('Get a list of assets');
// setup // setup