Giter Club home page Giter Club logo

nova-import-card's People

Contributors

bgmaxim avatar naoray avatar sparclex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nova-import-card's Issues

Validation messages more human readable

One suggestion with the error output could be to make it a little more readable? i.e. instead of outputting the row index then the column that needs attention, it could output something like

The value field in row 5 is required

Currently this would be output as;

The 3.value field is required

With the heading row ignored then 0 index for the first data row, A user may not understand that 3 is in fact row 5 in their import file.

Originally posted by @kombimedia in #1 (comment)

Laravel V6

Hi,
This package seems to be not compatible with laravel version 6
thx for response

Laravel v7

support for laravel v7, need to upgrade illuminate/support to atleast 7.0.

Card fields not respected

I have a situation where I wish to include an additional field in the card, but it seems that even though there was an intention to support customizing fields using a 'fields' meta field, it doesn't seem to be respected in the view.

Is anyone working on this?

Relateable rule

There's an issue, if you allow for relations to be set during import.

Laravel\Nova\Rules\Relatable:49 -> $this->query->select('*')->whereKey($value)->first()
The query doesn't ever reset, so on the second row being added it will keep adding another primary key check like this: where id= ? andid = ?.

This makes it fail

Class 'App\Providers\App\Nova\User' not found

Returned error: Class 'App\Providers\App\Nova\User' not found

After default Laravel Nova installation
Then installing package via composer:
"composer require sparclex/nova-import-card"

Then registering in "NovaServiceProvider.php" file

public function card()
{
return [
// ...
new \Sparclex\NovaImportCard\NovaImportCard(App\Nova\User::class),
];
}

Application returned error:

Class 'App\Providers\App\Nova\User' not found

In vendor\sparclex\nova-import-card\src\NovaImportCard.php

 */
public $width = '1/2';

public function __construct($resource)
{
    parent::__construct();
    $this->withMeta([
        'fields' => [
            new File('File'),
        ],
        'resourceLabel' => $resource::label(),// --- This line returned error

=================================
laravelnovaimportcard
laravelnovaimportcard

Illegal offset type

Hi @Sparclex ,

Thanks for the nice card!

However I am having an issue importing to a resource that has a computed field, receive an 'illegal offset type error'. If I comment out the computed field in the resource, everything works as expected.

Error message:
Illegal offset type {"userId":4,"email":"[email protected]","exception":"[object] (ErrorException(code: 0): Illegal offset type at /home/vagrant/websites/shoeboxchristmas/vendor/laravel/nova/src/Fields/Field.php:362)

There also seems to be an issue importing to a 'BelongsTo' field, unless it is not marked as 'required' in the resource. I need this to be a required field though.

Any ideas on fixes or work arounds for these issues?

Also are you considering adding field mapping? That would be really nice.. : )

A sample import file is attached (had to save it as 'xlsx' to attach).

Thank you in advance for any assistance.

This is my resource;

`<?php

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
use App\Nova\Metrics\Children;
use App\Nova\Metrics\Donators;
use App\Nova\Metrics\RegisteredShoeBoxes;
use Sparclex\NovaImportCard\NovaImportCard;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Fields\Select;
use Naif\Toggle\Toggle;
use App\School;
use Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel;

class Child extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'App\Child';

/**
 * The single value that should be used to represent the resource when being displayed.
 *
 * @var string
 */
public static $title = 'name';

/**
 * The columns that should be searched.
 *
 * @var array
 */
public static $search = [
    'id', 'name', 'donator_id', 'contact_name', 'contact_number',
];

/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
public static $with = ['school', 'donator'];

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ID::make()
            ->sortable()
            ->hideFromIndex(),

        Text::make('Ref', function () {
            $id = $this->school_id;
            $schools = School::where('id', $id)->get();
            foreach ($schools as $school) {
                return $school->code. '' .$this->id;
            }
        }),

        Text::make('Name')
            ->sortable()
            ->rules('required', 'max:255'),

        BelongsTo::make('School')
            ->rules('required'),

        Text::make('Age')
            ->sortable()
            ->rules('required', 'max:3'),

        Select::make('Gender')
            ->options([
                'Girl' => 'Girl',
                'Boy' => 'Boy',
            ])
            ->sortable()
            ->rules('required'),

        Textarea::make('Notes')
            ->rules('max:500'),

        Text::make('Contact Name')
            ->rules('required', 'max:255'),

        Text::make('Contact Number')
            ->rules('required', 'max:55'),

        BelongsTo::make('Donator')
            ->hideWhenCreating()
            ->searchable(),

        Toggle::make('Allocated')
            ->color('#3C8D0D')
            ->hideWhenCreating()
            ->sortable(),
    ];
}

/**
 * Get the cards available for the request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function cards(Request $request)
{
    return [
        (new Donators)->width('1/3'),
        (new Children)->width('1/3'),
        (new RegisteredShoeBoxes)->width('1/3'),
        new \Sparclex\NovaImportCard\NovaImportCard(Child::class),
    ];
}

/**
 * Get the filters available for the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function filters(Request $request)
{
    return [];
}

/**
 * Get the lenses available for the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function lenses(Request $request)
{
    return [];
}

/**
 * Get the actions available for the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function actions(Request $request)
{
    return [
        (new DownloadExcel)
            ->withHeadings()
            ->allFields()
            ->except('school_code', 'donator_id', 'deleted_at', 'created_at', 'updated_at')
            ->askForFilename(),
    ];
}

}
`

child-import-test.xlsx

Enable customization of the Card

Perhaps being able to set the sizing of the card and the label would be helpful.
This way if you end up needing 2 imports (for some reason like legacy reasons) on a single resource you don't wind up with the same named import cards.
A not so convoluted example would be like importing information about the resource and then perhaps pricing data if those 2 datasets come from different departments. It already works to just create 2 based off of different resources and use a custom importer, but the label on the "Import RESOURCE" just makes it so you have to create a whole resource for no reason.

Pass parameter to Import Class

Is this possible?

I have Cities that hasMany Users and User belongsTo a City.
I want to have an import card onlyInDetail of City resource that say Import Users.
And now, in excel file i do not want to include the city_id, i need to pass as parameter so all Users imported will belong to the City that the Import is executed.

In documentation what your package use is just the full path of class using Namespace: App\Imports\UserImport::class or 'App\Imports\UserImport'
Instead i want: new UserImport($city_id); lets say

If this is possible please tell me how to pass the parameter, if not, it will be great to have this as feature.

Thank you, great package btw

Extends BasicImporter

Hi,

I would like to extends BasicImporter because i have 2 more fields in my database than in my Excel so i would like to extends BasicImporter and i did that:



php

namespace App\Imports;

use App\Statement;
use Sparclex\NovaImportCard\BasicImporter;

class StatementsImport extends BasicImporter {
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Statement|null
    */
    public function model(array $row)
    {
        return new Statement([
            'date_publishing'     => date("Y-m-d", strtotime($row[0])),
            'date_value'    => date("Y-m-d", strtotime($row[1])),
            'operation' => str_replace("\\n", "\\r", $row[2]), 
            'debit' => abs($row[3]),
            'credit' => abs($row[4]),
        ]);
    }
    
}

But i still have error regarding missing fields (pointable & pointable_type) ... Let me know if you have a good example about Extend BasicImporter .. i don't know which kind of informations you need in attributes or rules or regarding Model

my data in Excel (d/m/Y for date)
image

my date in database: (Y-m-d for date)

image

my Migration :

        Schema::create('statements', function (Blueprint $table) {
            $table->increments('id');
            $table->date('date_publishing');
            $table->date('date_value');
            $table->text('operation');
            $table->float('debit')->default(0);
            $table->float('credit')->default(0);
            $table->integer('pointable_id')->nullable();
            $table->string('pointable_type')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

my Model:

class Statement extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'statements';

    protected $fillable = ['date_publishing','date_value','operation','debit','credit'];
    
    //Casts of the model dates
    protected $casts = [
        'date_publishing' => 'date',
        'date_value' => 'date'
    ];

    public function pointable()
    {
        return $this->morphTo();
    }

Result:
image

Thanks in advance,
Rémy

Adding more than one instance doesn't work as expected

I'm putting two of these on my dashboard page (e.g. one for users, one for product vendors) and when I do, picking a file for the second box puts it in the first, and picking a file for the first box puts it in the first.

A quick glance at the page's source suggests that the input's name HTML attribute is the same across all instances, there's a conflict going on there. Perhaps making a unique name for the field would work, such as name_product_vendor?

EDIT: Steps to reproduce:

  1. Add two instances of this card to the dashboard (or resource page)
  2. Click on "Choose File" on the second card and pick a file
  3. The file you picked appears in the first card, not the second.
  4. Expected behaviour: File you picked appears in the second card.

Issue on file uploading.

Nova Version: 1.3.1

Hi guys,

I'm facing the following issue when trying to import an excel file.
image

Anyone with same problem? I didn't customized anything, just using the standard process.

Thanks!

Enhancement to the title

Can the same styling be applied to the card title as default nova cards - make it

<h3 class="mr-3 text-base text-80 font-bold">Import Products</h3>

Error importing

Screen Shot 2019-04-01 at 18 34 23
Happens after selecting the CSV file and hitting import - I have the card registered ona Product resource as such:

new \Sparclex\NovaImportCard\NovaImportCard(Product::class),

Note: the docs say to reference the class through App\Nova\Model::class but this seems to repeat the App\Nova\App\Nova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.