Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a plugin for admin? #459

Closed
gauravt opened this issue Feb 5, 2015 · 18 comments
Closed

How to create a plugin for admin? #459

gauravt opened this issue Feb 5, 2015 · 18 comments

Comments

@gauravt
Copy link

gauravt commented Feb 5, 2015

I am working on an admin plugin where I am confused these part:

  • How to show the Admin navigation on the plugin template page?

There is not much documents available for it, please help.
Thanks
Gaurav T

@brianhyder
Copy link
Member

Take a look at the sample plugin, it provides an example for this:

https://github.com/pencilblue/pencilblue/blob/master/plugins/sample/sample.js#L45

@gauravt
Copy link
Author

gauravt commented Feb 5, 2015

I am already using it but when I am clicking on the navigation, admin navigation is not visible, sceenshot attached.
screenshot from 2015-02-05 17 42 39

@blakecallens
Copy link
Member

My guess is that there's an error in your code to add the navigation item. Can you share your main plugin file (products.js)?

@brianhyder
Copy link
Member

When that happens there is usually an angular error associated. Do you see
anything in the console output in the browser? If you look at the page
source is your admin navigation item in scope with the other nav items?
Does your nav item show up in any of the other admin screens?
On Feb 5, 2015 9:51 AM, "Gaurav Tewari" notifications@github.com wrote:

I am already using it but when I am clicking on the navigation, admin
navigation is not visible, sceenshot attached.
[image: screenshot from 2015-02-05 17 42 39]
https://cloud.githubusercontent.com/assets/1091887/6062296/92defd42-ad74-11e4-88e7-c92de28018d3.png


Reply to this email directly or view it on GitHub
#459 (comment)
.

@gauravt
Copy link
Author

gauravt commented Feb 5, 2015

Import.js

/**
 * CatalogImport 
 *
 * @author Brian Hyder <brian@pencilblue.org>
 * @copyright 2014 PencilBlue, LLC
 */
function CatalogImport(){}

/**
 * Called when the application is being installed for the first time.
 *
 * @param cb A callback that must be called upon completion.  cb(Error, Boolean).
 * The result should be TRUE on success and FALSE on failure
 */
CatalogImport.onInstall = function(cb) {
    cb(null, true);
};

/**
 * Called when the application is uninstalling this plugin.  The plugin should
 * make every effort to clean up any plugin-specific DB items or any in function
 * overrides it makes.
 *
 * @param cb A callback that must be called upon completion.  cb(Error, Boolean).
 * The result should be TRUE on success and FALSE on failure
 */
CatalogImport.onUninstall = function(cb) {
    // Remove "sample" nav during uninstall
        pb.AdminNavigation.remove("products");
    cb(null, true);
};

/**
 * Called when the application is starting up. The function is also called at
 * the end of a successful install. It is guaranteed that all core PB services
 * will be available including access to the core DB.
 *
 * @param cb A callback that must be called upon completion.  cb(Error, Boolean).
 * The result should be TRUE on success and FALSE on failure
 */
CatalogImport.onStartup = function(cb) {

    /**
     * Administration Navigation sample
     */

    // Add a new top level node
    pb.AdminNavigation.add({
        id: "products",
        title: "Products",
        icon: "cogs",
        href: "/admin/products",
        access: ACCESS_USER,
        children: [
            {
                id: "product_import",
                title: "Import Products",
                icon: "cog",
                href: "/admin/products/import",
                access: ACCESS_USER
            }
        ]
    });

    // Add a child to the top level node "sample"
    pb.AdminNavigation.addChild("products", {
        id: "products_modify",
        title: "Modify Products",
        icon: "cog",
        href: "/admin/products/modify",
        access: ACCESS_USER
    });

    // Add a child to the top level node "sample"
    pb.AdminNavigation.addChild("products", {
        id: "products_create_catalog",
        title: "Create Catalog",
        icon: "cog",
        href: "/admin/products/createcatalog",
        access: ACCESS_USER
    });

    // Remove "sample_2"
    //pb.AdminNavigation.remove("sample_2");

    cb(null, true);
};

/**
 * Called when the application is gracefully shutting down.  No guarantees are
 * provided for how much time will be provided the plugin to shut down.
 *
 * @param cb A callback that must be called upon completion.  cb(Error, Boolean).
 * The result should be TRUE on success and FALSE on failure
 */
CatalogImport.onShutdown = function(cb) {
    cb(null, true);
};

//exports
module.exports = CatalogImport;

@gauravt
Copy link
Author

gauravt commented Feb 5, 2015

screenshot from 2015-02-05 20 45 15

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.15/$injector/modulerr?p0=pencilblueApp&p1=E…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A17%3A431)

Yes, there is a error in console, see the screenshot

@blakecallens
Copy link
Member

Yeah, looks like @brianhyder was right. Have you created an Angular controller for the page?

@gauravt
Copy link
Author

gauravt commented Feb 5, 2015

No, Please can you help, I'm much interested in Pencilblue and wants to complete my work on it.

@blakecallens
Copy link
Member

Take a look at the Portfolio plugin's home page settings screen. That will give you an idea of how to create a custom admin screen for your plugin.

@blakecallens
Copy link
Member

Closed the issue, because we found what the problem was. You can still comment in this thread and we'll respond.

@gauravt
Copy link
Author

gauravt commented Feb 5, 2015

Any way to debug and log the variables to console.

@gauravt
Copy link
Author

gauravt commented Feb 5, 2015

One more question, How to create angularJS templates and is there any tutorials for it?

@blakecallens
Copy link
Member

  1. console.log() in JavaScript
  2. You can pretty much copy the Angular templates we have in the source. Tutorial will be coming later this month.

@gauravt
Copy link
Author

gauravt commented Feb 6, 2015

How I can create a template to upload files in Admin Panel?

@blakecallens
Copy link
Member

This is a much larger question than templates.

  • How are you hosting the site?
  • Where are you storing the files?
  • What kind of files are they?

@gauravt
Copy link
Author

gauravt commented Feb 7, 2015

Okay, Right now I am developing it on my local ubuntu machine and I want to import a csv file into the mongodb database and files needs to be saved into any folder under pencilblue.

@gauravt
Copy link
Author

gauravt commented Feb 9, 2015

I also want to know How to save some values in a array to the database?

@blakecallens
Copy link
Member

Take a look at the DAO's save function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants