Jump to content

Jonathan Lahijani

Members
  • Posts

    631
  • Joined

  • Last visited

  • Days Won

    23

Posts posted by Jonathan Lahijani

  1. I love ChatGPT when it comes to doing weird things in JavaScript.  For example, there's a 3rd party service a client of mine is using that allows you to load in custom JS and CSS to customize the appearance of their platform more to your liking.  The HTML of the 3rd party service is lacking in some CSS classes on some elements, so I can't hook into those elements to style them more precisely.  To further complicate things, those elements only appear after an AJAX request is done.

    So I needed to add extra classes on particular elements in the HTML every time an AJAX request was made.  I don't keep up with JS, but after giving it a nice prompt, BOOM, there's the answer with MutationObserver, XMLHttpRequest and addEventListener.  This literally saved me a day, if not more, and tons of headache.

    • Like 6
  2. ProcessWire stores the users in /admin/access/users/.

    This means if you want to view the user list in the page tree, you have to click into it and that's not ideal.  It would be better if the Users were just presented as if they were nested under the Home page.

    Approach 1: actually move Users under Home (avoid this; explanation)
    While I haven't tried it (and have no plans to), you could do what Ryan described in this article a long time ago, this but it's probably dangerous and overkill:
    https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users

    Approach 2: fake it! (better and very easy)
    What would be better for some is to have it appear as if the Users were directly under the home page, but without actually having to move the Users page itself as it could break ProcessWire functionality.  This can be accomplished easily with the following hook (add this to /site/templates/admin.php):

    // make Users appear as nested under Home page
    $wire->addHookAfter('ProcessPageList::find', function(HookEvent $event) {
      if($event->arguments('page')->id!=1) return;
      $event->return = $event->return->prepend(wire('pages')->get('/admin/access/users/,include=all'));
    });
    • Like 3
  3. I need to develop a RESTful API in ProcessWire.  While I haven't developed one before, I am fairly comfortable with the general idea.

    There are separate PHP frameworks that specialize in this, as well as specific ProcessWire modules, however I want to do this purely with ProcessWire.  I haven't seen discussion on this, but my thinking is the necessary features are there to make this happen, which are:

    Any thoughts on this or recommendations?

  4. On 9/22/2023 at 12:47 PM, ryan said:

    Last week we had a big update of Pro modules and this week we have another batch of Pro module updates. These are now posted and available for download in the relevant boards: 

    Hi Ryan,

    Would it be possible to create a more streamlined way for your 1st party commercial modules to be downloaded?  I have licenses for most of them and grabbing them all one-by-one through the respective forum threads is less than ideal.  Too much friction.

    Ideally, if they could be upgraded via ProcessWireUpgrades module (although I think I understand your hesitation doing it that way), or if there were some sort central control panel on processwire.com/talk/ (or just processwire.com), that would be a nice upgrade.

    • Like 6
  5. 10 hours ago, Ivan Gretsky said:

    @Jonathan Lahijani, would you mind elaborating on this a bit? How do you manage your frontend without node based build chain? I am very interested as I am moving along a similar path, having ditched gulp. Now I do not even concatenate my js leaving it to http2. The only thing i still compile is scss) How do you do it nowadays?

    My use of Node was as follows (well it was based on Laravel Mix):

    • downloading packages (package.json / node_modules); for example, getting UIkit, jQuery and whatever else a project required
    • compiling SCSS or Tailwind
    • creating a dist folder with that CSS, other compiled JS and images
    • cache busting

    As for downloading packages, I have my own ProcessWire module that contains unminified and minified versions of the packages I commonly use or that I deem to be worthy enough to be in the module.  I built a very simple way to update those packages and include them in my project as well as well.  UIkit is a special case in that it's both SCSS and JS files.  If I want to include HTMX for example, I just do this:  setting('htmx-enabled', true); and everything gets inserted as it should.  The potential drawback of this approach is that because I use this module across many different projects, all projects automatically get upgraded to the latest version of a package which could potentially break things, but that's rare and not a big issue for me.

    For compiling SCSS, I would have stuck with ProCache (SCSSPHP) but it's completely outdated and that's just not going to change.  Therefore I use DartSass.  You can download the executables here:
    https://github.com/sass/dart-sass/releases
    I've hacked ProCache (because it doesn't have the necessary hooks) so that instead of using SCSSPHP, it uses DartSass.  Ryan has expressed the ability for ProCache to be more friendly to using outside compilers so hopefully a future version of ProCache doesn't have to be hacked directly.

    As for Tailwind, during dev I use Tailwind Play CDN.  During production, similar to DartSass, I use TailwindCSS CLI and I hacked ProCache to make it work with it as well:
    https://tailwindcss.com/blog/standalone-cli
    https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.3.3

    Both DartSass and TailwindCSS CLI have minifiers built-in, so therefore I avoid using ProCache's CSS minifier which has been a a little buggy (although I think it's now fixed?).  Technically speaking, TailwindCSS CLI is Node.js under the hood, but it's wrapped up into one executable which feels clean.

    For what would typically be a "dist" folder, I just avoid that.  ProCache Buster handles that in its own way.

    8 minutes ago, Ivan Gretsky said:

    AFAIK unpoly does not have an analogue to AlpineJs. In fact, unpoly users seem to also adopt AlpineJs for the frontend stuff.

    It is more a complete (and more opinionated) replacement for htmx though.

    Yea these is how I think about it as well.  HTMX is less opinionated and I like it that way.  However HTMX is not the "JS sprinkles" (it's more for HTML over the wire requests) so that's where Alpine.JS comes in.

    • Like 4
  6. Just now, wbmnfktr said:

    I have had the very exact thoughts about this for quite some time. 
    What are your reasons here, beside super heavy JS-frontends (React, Preact, Nuxt, Next,...)?

    That's pretty much the main reason.  It would require me to use ProcessWire in a different way and I don't buy into that approach, especially with HTML Over The Wire (for example, htmx) giving me all the benefits of heavy JS-frontends without having to use them.  Server-side rendering all the way.  I've completely eliminated Node from my workflow and it feels great.

    • Like 5
  7. On 9/8/2023 at 7:04 PM, wbmnfktr said:

    I played around and worked a lot with Astro in the last few months, and one thing I really liked was working with <Components />.

    I've heard of Astro and a bunch of other JS heavy frontend frameworks where ProcessWire has to become an API for it to work.  Hard pass for me for so many reasons.

    On 9/9/2023 at 2:32 AM, Ivan Gretsky said:

    Here is a nice article by Dave Rupert I've found on the topic. Didn't try any of it (yet?) though.

    This article is exactly what I was looking for.  Thank you for sharing it!

    21 hours ago, ngrmm said:

    I write scss, but only because of lacking css nesting support.

    It seems nesting is available on all the latest browsers, but I'd worry about people on old versions of Safari due to being on old versions of macOS (Macs seems to last a while), so yea I agree with using a build process for now if nesting is critical to the way you write CSS, which it is for me as well.  Also, doing breakpoints in SCSS in much more intuitive than vanilla CSS.

    • Like 3
  8. @ryan Can ProCache be refactored in such a way that SCSSPHP and the other compilers are optional extensions, along with the ability to define our own compilers (ie, DartSass and TailwindCSS CLI)?  You mentioned something along those lines in a conversation we had in the ProCache forum and I think this would be a step in the right direction given how fast things in frontend web development move.

    • Like 5
  9. Given that CSS has made huge strides in recent years combined with my desire to remove build processes (Sass, Tailwind), I'm thinking about going back to writing vanilla CSS, at least for some projects.  My question is, what CSS organization methodology makes the most sense for vanilla CSS?  I was never a fan of BEM personally and haven't had to think deeply about CSS methodologies for the past 10 years because I just followed the style of whatever CSS framework I was using.

    • Like 1
  10. Just now, Jan Romero said:

    This helped me give in to my nagging coworkers and sign up for ChatGPT, but I can’t seem to get it to answer this question properly? May I ask what your prompt was, @Jonathan Lahijani? Also, what’s causing problems with calling ready() explicitly?

    ChatGPT has blown my mind countless times from a programming point of view.  It's ridiculously helpful and has given me superpowers (ie, less reliance on poor Google results, which in turn helps with learning faster).  It's also very helpful in providing a starting point on topics I have low experience in (for example, doing some advanced things with ImageMagick).

    My prompt was literally copy/paste of my original post.  Pretend ChatGPT is a human that knows basically everything about everything.

    I have a bunch of other code in ready() which was causing errors given the context.  But I should investigate that further (I was losing patience debugging for 2 hours).  Will try what Ryan mentioned, but for now I refactored my hooks into their own method.

    • Like 1
  11. I asked ChatGPT and it gave me what I needed to know:

    Quote

    When a module is installed, it gets added to the list of active modules and its ___install() method is called (if it exists). However, the ready() method isn't immediately triggered upon installation. The usual lifecycle of the module involves it being loaded and initialized during the bootstrapping process, and then the ready() method is called when ProcessWire has fully initialized.

    By trying to execute setupDemo() right after the installation, you're not giving the module a chance to reach the "ready" state, and therefore the hooks aren't being attached.

    Therefore, I've moved the relevant hooks into a method outside of ready() and am attaching the hooks explicitly now in my script.

    • Like 1
  12. I have a module that I created which I am installing and then running a method on via the command line (although this issue still occurs when running in the script in my browser as well).

    My script looks like this (I've heavily simplified it here to demonstrate the issue precisely):

    <?php namespace ProcessWire;
    include(dirname(__FILE__).'/../index.php'); // bootstrap processwire
    
    wire('modules')->install('MyModule');
    wire('modules')->get('MyModule')->setupDemo();

    MyModule's ready() method contains various hooks, many of which do things on page save.
    MyModule's setupDemo() method does a bunch of stuff like creating pages and fields.

    The problem is, when doing those two things back-to-back as shown above, the ready() method doesn't get executed for some reason and therefore the hooks do not get applied!  As a result, the various things that rely on hooks in setupDemo() do not execute.

    If I were to split the two method calls into two different scripts and ran them one after another, this issue does not occur.

    What am I doing wrong?

    I've tried wire('modules')->refresh(); between the two calls and several other things but no luck.  Note: if I call the ready() method explicitly, it causes problems as well.

    • Like 1
  13. I had my own similar moment today.  I was using the API to install a Fieldtype module, such as FieldtypeToggle.  It was not working and after an hour of debugging, I found out I had capitalized the T in Fieldtype (FieldTypeToggle -- bad!) which ProcessWire doesn't play nicely with.

    • Like 1
    • Haha 1
  14. The problem I had was with the way I was using the head-support extension.  I was using the "merge" behavior instead of the "append" behavior.  Merging would destroy all Tracy injected code that it placed in <head>, but appending preserves it.  Appending leaves a bit of extra HTML behind after HTMX does its merge, but it doesn't affect how a page gets rendered or lead to incorrect results.

     

    • Like 3
  15. On 2/15/2023 at 11:42 AM, Jonathan Lahijani said:

    Tracy's interface in the frontend seems to fall apart when using HTMX boosted links:
    https://htmx.org/docs/#boosting

    Has anyone had experience with this and know how to fix it?

    An update on this as I now know what the problem is... 

    If using TracyDebugger with HTMX's head-support extension, TracyDebugger's bar will become "unstyled" when doing an htmx-style request.  This happens because the CSS that TracyDebugger uses to style the bar gets stripped-out with that extension (since it's in the <head> and the two don't play nicely with each other).  I will follow up with a solution if I'm able to find one.

    • Like 2
  16. I find myself continuously running various commands that interface with ProcessWire while developing a site.  For example, I may want to delete all the orders in the ecommerce site I'm currently developing.

    My approach for a while has been to have a bunch of 1-off PHP scripts that I'd run (either via command line or through a link since it's publicly accessible), but I was wondering if there's a more formal way to do this with ProcessWire.  Laravel has Artisan, Craft CMS has Console Commands for example.  I think wire shell (wtf the forum software keeps breaking this word up) solved this but it's abandoned (sadly).

    Any recommendations?

  17. On 5/19/2023 at 12:56 AM, bernhard said:

    @Jonathan Lahijani why don't you just use a separate config-local.php where you set guestForceDevelopmentLocal = true?

    Such a dedicated config has a lot of other benefits like disabling sessionFingerprint to make sure you don't get logged out when you enable mobile view in devtools or filesOnDemand when using RockMigrations:

    @bernhard My current strategy for detecting development/staging/production environment is currently based on using gethostname() or server_name, depending on the site and setting a custom $config->env variable.  Eventually I will switch to a cleaner way when Ryan hopefully officially implements something more formal.  I saw your PR and have read the various discussions on this topic.

    That aside, I would still want guestForceDevelopmentLocal to apply specifically to myself (based on IP or some other method) because sometimes I let people view my local dev environment from the outside and I don't want them to see the debug bar.

    • Like 1
  18. How would I halt output of a template file using return $this->halt(); but with that code not actually appearing in the template file itself?

    In short, I want to halt output of a template file at some point using the halt method described, but I want to have it be done more flexibly, meaning I want that code to exist within my ready.php for example (or just somewhere not in the template file).  What's the best way to do this?

    I don't want to use exit because it has unintended consequences.

×
×
  • Create New...