Jump to content

Recommended Posts

Martin: Thanks!

Ryan: what would be best approach, if I would like to create sitemap for AdminBar? Or any other "customized" page?

My initial plan is this:

Check if there is template called "AbminBarPage"

->if not, create template (title & body fields)

Check if there is page /adminbar/sitemap/

-> if not, create page

-> put needed code into body

It would be probably good idea to actually produce each view as AdminBarPage, then this module wouldn't break on changes on admin templates (or if some site has custom admin etc).

Share this post


Link to post
Share on other sites

These are just thoughts, but my first idea was that it would provide full site map (well, maybe not full if there is very deep levels..) in open state, show clearly where the current page is. Then of course links to move to other pages. Probably no need to edit, move etc (since these are easily done through real admin).

In short: to provide quick look over the whole site and where the current page is.

Share this post


Link to post
Share on other sites

I made some progress here.

Most important thing first: PW source is very well documented and it just makes sense! After half an hour I started guessing method names and usually got them always right :P

I have now version working, where I create adminbar-template (with fieldgroup & title field), adminbar-templatefile & and finally create the page. I'm not sure if this is right way to go, but I see huge benefits this way:

  • Template-files that adminbar uses goes to site/templates/adminbar folder, so they are easily customized per site basis
  • We could have ie. "Information for content editors" field that is showed everyone who is editing content etc. Maybe more settings per different view etc?
  • This gives full control to create modal views as I like them to be - easier to develop than hooking. Of course there we have to be careful not to re-invent the wheel and keeping UI consistent with other aspects of PW

Only negative things I can think of now are

  • More templates, more pages, more templatefiles...
  • But probably just a good thing, if those can be visible only to superadmins (I don't know yet how UA works)

This was quick hack, but if Ryan confirms that this is not worst way of developing AdminBar further, I'll probably go forward and implement this at least on the views that current admin doesn't provide (I know correctly this means only the "full sitemap view" so far).

Share this post


Link to post
Share on other sites

re: content editors: just a note: as Ryan previously stated, everything about Users [user roles, intercommunication, data information, versioning] is mostly in very crude, unpolished state – because Pages and overall API had hightest priority. Therefore, for few things there are no solutions currently [who's editing what, etc]

Share this post


Link to post
Share on other sites

I have it working nicely... almost :) One little problem that I cannot figure out. For some reason this code gives me HTTP-error 500, but only once (first time it runs). Probably some silly error (I create stuff on wrong order or something similar..? Or save() doesn't return the object I assume it returns? Ryan, any ideas what I am doing wrong?

I have also attached full module if anyone is interested to try. There is one new feature and it is quick collapse-enabled sitemap to show where the current page is located and to quickly move around your site.

I know this code could be cleaned up a lot, but be gentle - I am just learning this stuff :)

private function _createAdminBarPages() {
	$abName = "adminbar";
	$abFieldGroup = $this->fieldgroups->get($abName);
	$abTemplate = $this->templates->get($abName);
	$abPage = $this->pages->get("/processwire/{$abName}/");

	if(is_null($abFieldGroup))
		$abFieldGroup = $this->_createAdminBarFieldGroup($abName);

	if(is_null($abTemplate))
		$abTemplate = $this->_createAdminBarTemplate($abName, $abFieldGroup);

	if(!file_exists($abTemplate->filename()))
		$this->_createAdminBarTemplateFile($abTemplate);

	if(!$abPage->id)
		$abPage = $this->_createAdminBarPage($abName, $abTemplate);

}

private function _createAdminBarFieldGroup($fieldGroupName) {
	$abFieldGroup = new Fieldgroup();
	$abFieldGroup->name = $fieldGroupName;
	$abFieldGroup->add("title");
	return $abFieldGroup->save();
}

private function _createAdminBarTemplate($templateName, $abFieldGroup) {
	$abTemplate = new Template();
	$abTemplate->name = $templateName;
	$abTemplate->setFieldgroup($abFieldGroup);
	return $abTemplate->save();
}

private function _createAdminBarPage($abName, $abTemplate) {

	// create /adminbar/ page under admin
	$abPage = new Page();
	$abPage->template = $abTemplate;
	$abPage->parent = $this->pages->get("/processwire/"); // TODO: How to remove hardcoding admin url??
	$abPage->title = $abName;
	$abPage->name = $abName;
	$abPage->status = 1031; // hidden & locked
	$abPage->save();

	// after that create /adminbar/adminbpar-sitemap/
	$abSitemapPage = new Page();
	$abSitemapPage->template = $abTemplate;
	$abSitemapPage->parent = $abPage;
	$abSitemapPage->title = $abName . '-sitemap';
	$abSitemapPage->name = $abName . '-sitemap';
	$abSitemapPage->status = 1031;
	return $abSitemapPage->save();
}

private function _createAdminBarTemplateFile($abTemplate) {
	copy(dirname(__FILE__)."/pages/sitemap.php", $abTemplate->filename());
}

AdminBar.zip

Share this post


Link to post
Share on other sites

Apeisa,

I tried this out and it works great! Nice work. The site map view is very useful too. Also, I think the code looks good! Here's a few suggestions and notes I've got:

The 500 error you got was thrown by ProcessWire. The problem is these lines:

return $abFieldGroup->save();
return $abTemplate->save();

All the save functions return a result status, basically true if it was successful, false if not. So to fix the error, you would need to change lines like the above to:

$abFieldGroup->save();
return $abFieldGroup;

$abTemplate->save();
return $abTemplate; 

When you are developing in ProcessWire, you may want to enable debug mode, so that errors are echoed to the screen. You can turn this on in /site/config.php. Look for the line that says $config->debug = false; and change it to true.

Next, I wanted to mention that the module interface provides install() and uninstall() methods, in case you want them:

/**
* Perform any installation procedures specific to this module, if needed. 
* 
* This method is OPTIONAL
*
*/
public function ___install();

/**
* Perform any uninstall procedures specific to this module, if needed. 
*
* This method is OPTIONAL
*
*/
public function ___uninstall();

There may be issues on many installations with your last function, _createAdminBarTemplateFile. The reason is that ProcessWire doesn't usually have write access to the templates dir (it depends on the server). So your installer may be want to look for this, or advise them to copy your template file in there if there isn't write access. Or, we could just make it a blank template (without a file) and then hook into it's render method so that your .module file can render the output instead. Let me know if you want to do that, and I can provide instructions.

Lastly, because the site map outputs a full sitemap, it may not scale to large installations. For instance, the site I am working on now has 5k+ pages, and while it renders them all, it takes several seconds. :) But on large installations, it might just run out of memory too. As a result, I would recommend placing a limit to the number of subpages that the sitemap will display. Maybe a "limit=50" per branch, just to account for the possibility of large sites. And once it reaches that limit, it might have a label that says "Go to the admin to view remaining pages" or something like that.

Again nice work on this, I am really enjoying using this module!

Share this post


Link to post
Share on other sites

Ryan, thanks for your answer. I wasn't sure about the write access on template dir (I develop on windows when there is basicly always write access).

So your installer may be want to look for this, or advise them to copy your template file in there if there isn't write access. Or, we could just make it a blank template (without a file) and then hook into it's render method so that your .module file can render the output instead. Let me know if you want to do that, and I can provide instructions.

Hmm.. I think that the latter is better. Or maybe both? If there is template file -> use that. If not -> render. Is that possible? The first reason I went for this "copy template file" route was that I didn't know any other way to make this work :)

Share this post


Link to post
Share on other sites

I think it might be better to just override the template rather than putting one in the /templates/ dir (unless you want to encourage them to edit it). I've modified the Template class so that you can change the target filename at runtime, so you'll want to grab the latest commit.

https://github.com/ryancramerdesign/ProcessWire/commit/0c8dc7d8e62c9a6a110791e00111c463ff00b01c

Next, move that template to the same directory as your module (/site/modules/AdminBar/adminbar.php).

Then in your AdminBar.module, add a new "before" page render hook. It will check to see if the page template is "adminbar", and if it is, it'll change the template filename to the one in your /site/modules/AdminBar/ dir.

<?php
public function beforePageRender($event) {
    $page = $event->object;
    if($page->template == 'adminbar') {
        $page->template->filename = $this->config->paths->AdminBar . "adminbar.php";
    }
}

Also, add this to your init() function in AdminBar.module:

$this->addHookBefore('Page::render', $this, 'beforePageRender');

If you do decide you want it to check if the file is in your /site/templates/ first, then just add that check to your beforePageRender method.

Now it should work exactly the same as before, except that it'll use the template file in your /site/modules/AdminBar/ dir rather than expecting one to be in /site/templates/.

Share this post


Link to post
Share on other sites

Lastly, because the site map outputs a full sitemap, it may not scale to large installations. For instance, the site I am working on now has 5k+ pages, and while it renders them all, it takes several seconds. :) But on large installations, it might just run out of memory too. As a result, I would recommend placing a limit to the number of subpages that the sitemap will display. Maybe a "limit=50" per branch, just to account for the possibility of large sites. And once it reaches that limit, it might have a label that says "Go to the admin to view remaining pages" or something like that.

I created this functionality and noticed that $page->numChildren gives num of all children (hidden also). Is there some selector that I can use to count only visible children?

Share this post


Link to post
Share on other sites

Well.. there is small bug. After deleting a page we get this error:

Call to a member function isAjax() on a non-object (line 62 of C:\apache\htdocs\pw\wire\core\admin.php)

This error message was shown because you are logged in as a Superuser.

This must be because of modal somehow? Deleting pages sends them to thrash (so it works), but we still get that error. I could just disable delete-tab on modal, but I think that is a nice feature. Any clues on this one Ryan?

Share this post


Link to post
Share on other sites

I should sort it out for IE, finally. But, unfortunately, no time :( I should also style that hide link a little {maybe another glyph?}

good work Antti.

Share this post


Link to post
Share on other sites

I should sort it out for IE, finally. But, unfortunately, no time :( I should also style that hide link a little {maybe another glyph?}

good work Antti.

Thanks Adam. And no reason for stress because of this, early days and most important thing is to learn module dev.

If someone has plans to use this on client site then please us know and we'll fix the "browser".

Share this post


Link to post
Share on other sites

I created this functionality and noticed that $page->numChildren gives num of all children (hidden also). Is there some selector that I can use to count only visible children?

There is. Try this:

$total = $page->children("limit=2")->getTotal();

You have to do "limit=2" (or higher) rather than "limit=1" because PW2 doesn't currently count totals on limit=1 selectors. That's just as a matter of efficiency, since all $pages->get() functions use limit=1 internally.

Share this post


Link to post
Share on other sites

This must be because of modal somehow? Deleting pages sends them to thrash (so it works), but we still get that error. I could just disable delete-tab on modal, but I think that is a nice feature. Any clues on this one Ryan?

I'm not sure why that error was turning up, and am out of time to take an in-depth look, but I was able to fix it easily. And actually I think it's something I should have had in there in the first place (an extra check to make sure that $controller is not null), so thank you for finding it. :) I have fixed this in the latest commit:

https://github.com/ryancramerdesign/ProcessWire/commit/99454cb68b0ccfe287ab82c68c9db7010a6f94be

AdminBar is looking great! Would you mind if I tweeted a link to your screencast?

Share this post


Link to post
Share on other sites

Updates: IE is fucking nightmare:


  •  
  • minor updates on github
     
  • still old readme [wanted to do the markdown version, no chance
     
  • IE7 isn't supported even by the PW Admin, no prob there [iE6 wasn't even tried]
     
  • IE8 is doing something funky with z-index, so hover doesn't work. I solved the width, but this is killing me. Also, BG of overlay isn't showing (because IE8 doesn't know rgba colors)
     
  • IE9 can't be virtualized in XP, and I don't have Win7 virtualized currently [neither install CD]. Also, IE9 is beta, so no hard feelings there

This should be it, I might look on the site tree later on too, because it's fugly.

Also I'm pissed, nothing works tonight. Good night, more updates tomorrow or later.

Share this post


Link to post
Share on other sites

I'm not sure why that error was turning up, and am out of time to take an in-depth look, but I was able to fix it easily. And actually I think it's something I should have had in there in the first place (an extra check to make sure that $controller is not null), so thank you for finding it. :) I have fixed this in the latest commit:

https://github.com/ryancramerdesign/ProcessWire/commit/99454cb68b0ccfe287ab82c68c9db7010a6f94be

AdminBar is looking great! Would you mind if I tweeted a link to your screencast?

Thanks for the fix. And sure you can tweet the screencast.

Share this post


Link to post
Share on other sites

I merged Adam's changes to adminbar. Also took cleaning further: I removed other options than modal and also cleaned js & css even more. It should work in IE now (I have only IE9 on my home computer and it works on that now. I am pretty confident that it works ok in other IE:s too - but no promises here :)).

Reasoning for taking options out: I think shortcuts will be the actual view that everyone uses: editing & creating will be done there. "Main" view will be for looking more information: who edited and when etc (hope to make that better later). And I think admin link should always take to admin front.

Also: I think this as real 1.0 release. I'll fix all the bugs that people may a rise, but any new features will be added with care. Of course all the optimizing to code and UI are most welcome (from Adam or anyone who is interested in contributing).

Share this post


Link to post
Share on other sites

I receive error when installing:

Exception: Can't save page 0: /adminbar/: It has no parent assigned (in www\phreshr.tv\wire\core\Pages.php line 337)

#0 [internal function]: Pages->___save(Object(Page))

#1 www\phreshr.tv\wire\core\Wire.php(241): call_user_func_array(Array, Array)

#2 www\phreshr.tv\wire\core\Wire.php(203): Wire->runHooks('save', Array)

#3 www\phreshr.tv\wire\core\Page.php(733): Wire->__call('save', Array)

#4 www\phreshr.tv\wire\core\Page.php(733): Pages->save(Object(Page))

#5 www\phreshr.tv\site\modules\AdminBar\AdminBar.module(312): Page->save()

#6 www\phreshr.tv\site\modules\AdminBar\AdminBar.module(284): AdminBar->_createAdminBarPage('adminbar', Object(Template))

#7 ww

This error message was shown because you are logged in as a Superuser.

Any suggestions on whats wrong? It had worked briefly. Then all of a sudden it didn't. I'm on a wamp stack and using php 5.3.5.

Share this post


Link to post
Share on other sites

Thanks for trying AdminBar and sorry for problems.

Error is probably that I have hardcoded the /processwire/ site as admin site. If you have renamed your admin (so that url is not /processwire/), then it will fail like that. You can make quick fix by editing two lines (chance them to have your admin page url):

https://github.com/apeisa/AdminBar/blob/master/AdminBar.module#L275

https://github.com/apeisa/AdminBar/blob/master/AdminBar.module#L308

I'll take a look how I could remove that hardcoding later today (I tried that earlier, but didn't work - Ryan, any clues? Probably some silly typo I had there...).

Share this post


Link to post
Share on other sites

You can get the admin URL from:

$config->urls->admin

Or if you want to retrieve the admin page:

$admin = $pages->get($config->adminRootPageID); 

Btw, I don't often do it, but it is good security to change your admin page name. You do this by editing it, clicking on the 'settings' tab and changing the name.

Share this post


Link to post
Share on other sites

Btw, I don't often do it, but it is good security to change your admin page name. You do this by editing it, clicking on the 'settings' tab and changing the name.

Heh, I made this and got redirect to 404. I thought it was somehow because of AdminBar.. but it wasn't. Spend few minutes itching my head and disabling all redirects on AdminBar.module... :)

Thanks for the tips Ryan. Now AdminBar works with any admin url, latest files are on GitHub.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild. 
      EDIT: You can now install it directly from the Modules directory: http://modules.processwire.com/modules/inputfield-float-range/
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Optional step value (Read more) Optional manual override of the selected value (will still adhere to the rules above) Configurable rounding of manually entered values (floor, round, ceil, disable) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant  
      Changelog
      004 (current version)
      - Make rounding of manually entered values configurable (floor, round, ceil or disable)
      - Fix small JS bug when the value-display field was not displayed
      - Update README
      003
      - Code cleanup, add some ModuleInfo data & LICENSE
      - Submit to PW Modules directory (http://modules.processwire.com/modules/inputfield-float-range/)
      002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional
      001
      - Initial release
       
      Thanks!
       
       
    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-10-18
      2019-08-08
      2019-06-15
      2019-06-02
      2019-05-25
      If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
×
×
  • Create New...