laravel 5; redirect to previous section after store or view - redirect

I think this is a basic problem or question, but i can't find any solution that solves this problem, so probably i'm searching in the wrong way or on the wrong keywords.
I have a bunch of articles in my DB, and there are a number of ways to read/edit them on the site.
- The visitor can see them in a list, click on them and read the whole article
- The registered users can see them in the same list, but click on them to read or edit the article
- The admin can see a different list (an different view), and edit or delete them
and i'm sure i will come up with some other ways to read or edit the articles or other data.
The point is, that if a visitor or user had read or edited the article, i want them to return to their own index of articles, but if an admin has read or edited the article i want him to go back to the admin-index.
So from the start i have a number of routes:
Route::get('/article'... will display the index of articles
Route::get('/article/{name}'... will display an article
Route::get('/article/{name}/edit'... will display the edit form for the article
Route::post('/article/{name}'... will update the article
And for the admin:
Route::get('/admin/article'... will display the index of article
Route::get('/admin/article/{name}'... will display an article
Route::get('/admin/article/{name}/edit'... will display the edit form for the article
Route::post('/admin/article/{name}'... will update the article
But..Route::post('/article/{name}' and Route::post('/admin/article/{name} should point to the same function to update the data, and that function should redirect to different routes, in this case Route::get('/article' and Route::get('/admin/article'
I really dont want to write 2 different routines to store or update the data in the database, that are in fact the same, except for the 'redirect'-line after updating or storing.
My first thought was to make 2 routes, with two entries in my controller that each call the same routine that saves the data, and return where i can redirect, but then i would have to use different 'actions' in my form. That would mean i would have to make 2 forms that are the same, except for the 'action'-line.
Whatever i do, i would have to redirect somewhere based on the section of my site where i was before i started to read or edit my data.
I read something about the 'back()'-function, but that won't help me because i want to be able to read an article, and then choose to edit it, then return back to my index.
I hope i was able to explain what i want to do, and i'm sure i'm not the only one looking for this, but again, i failed in finding a right solution.
What is het best way to achieve this?!?

I would just separate the controllers between normal users and admin users. This way your code will stay clean and understandable.
You could for example make the following folder structure:
app
- Http
- Controllers
- Admin
- User
Don't forget to change the namespace in your controllers.
If you really want to stick with the same controller for both users then you need to make some kind of if else statement to see what kind of user your are dealing with and redirect on that outcome. Do you have some kind of role structure in your application?

Related

Reorder Umbraco to have Articles/Year/Month/Article map structure

I have a website that's been running for over a year. The overview is getting lost in the Articles doctype and I've been asked to change the file structure from Articles/Article to Articles/Year/Month/Article.
In short, the admin opens Umbraco and sees the Articles and clicks the arrow to see all the articles. It then takes a couple of minutes since the are all loaded. Instead I want a map structure that devides the articles into year and month published.
Since i'm talking about 5k articles, I can't really do this manually.
Any advice?
You could do 2 things:
Create a simple script which moves all articles into a year/month folder structure. Should be pretty simple to make.
Add a List View content type on your "Articles" template. It will give a searchable list with all 5K articles. It will prevent the loadtime in Umbraco UI. You can see how the list view works here: http://www.robertgray.net.au/posts/a-first-look-at-umbraco-container-content-types
You need to look at the UrlProvider and ContentFinder configuration in your umbraco instance.
Shouldn't require any manual editing of the articles provided they were posted on the days you would like them to display as.
Take a look at this: https://24days.in/umbraco-cms/2014/urlprovider-and-contentfinder/

Adding specific number of sections in a google form

When an user enters a number into a field (representing the number of persons in a group), I want to have a section of google forms to be multiplied that many times - one for each person. In each such section I need to enter their details. Anybody did something similar to this ?
I think what you're trying to do isn't possible (without using App Scripts) but I have built a little example of something that might work for you. Please see if this will work and get back to ASAP.
Pretty much it has a title page asks the user how many people they want to sign up. Then, depending on the answer, the form directs them to a section with the appropriate number of sign-ups.

confluence display content by user

I am trying to get specific content on a confluence cloud wiki to display content based on a specific user. The scenario here is that there are links on a page but only 1 should display, the one that displays is based on whom ever is logged in.
I have been told how a macro is the way forward, but I have read the documentation and I am at a loss. I do not understand what I have to do or how to write a confluence macro. could someone help me out with either an example or some links? I have searched like crazy, but maybe i am not asking the right questions but hopfully you can all help me out?
There's a plugin for this:
https://marketplace.atlassian.com/plugins/net.customware.confluence.plugin.visibility
But I'm not sure how thoroughly it hides the content. It might still be visible if users view the page source. If you're trying to hide content which needs to be really protected, you'll probably need to do something else.
Depending on how many users are going to be using the page, you could also just make separate spaces for them, add the permissions to those spaces, and then use a page-include on your "main" page to display the content. If they don't have access it shouldn't show up. You might experience some formatting issues with that solution, however.
Finally, you could grab the username with jquery and display stuff based on that. This solution will be pretty easy if you are familiar with javascript/jquery.
Edit: Here are some helpful resources on how to use javascript and jquery within confluence:
https://confluence.atlassian.com/display/CONFKB/How+to+Use+JavaScript+in+Confluence
https://developer.atlassian.com/confdev/confluence-plugin-guide/writing-confluence-plugins/including-javascript-and-css-resources

How to track checkboxes with Django and endless pagination?

I am a Django noob and have a situation that goes beyond the basic documentation, etc.
I am updating an ordering webpage that has a form structured as follows:
several text boxes, etc to gather general info (name, date, etc)
two separate tables for selecting (via checkbox) catalogs that are generated/managed using endless_pagination. Each table can have thousands of records, hence the endless_pagination. The first column in each table is a checkbox with value = catalog.id.
a textbox where the user can manually enter catalog IDs
a submit button
I am not sure how to keep track of what a user has selected in the two paginated tables since the checked boxes are lost when choosing a different page. Also, when the user flips back and forth between the pages, the previoulsy checked catalogs will need to be re-checked(since the checked state is not maintained). I am also not sure which tool(s) to use to deal with this.
My thought is to use JavaScript (with which I have minimal experience) to update a list of catalog IDs whenever a checkbox is checked/unchecked and:
- and attach that list to the form or
- update a variable in the form or
- send as a variable separate from the form, whichever is possible/makes more sense.
I'm hoping that maintaining a list of catalog IDs is possible because the next iteration of this form will likely include some sort of filtering so I'm trying to devise a solution that will not have to be reworked later.
I have reviewed a lot of posts but I believe the closest solutions are rendered useless because of the endless_pagination.
Let me know if further clarification is required. Thanks in advance for any suggestions.
UPDATE
I tried using JavaScript to store the catalog IDs in an array when a checkbox is checked. This does not work when a user selects another page in the pagination. The array of checked catalog IDs is lost when the page 'reloads'.
I'm running into this problem right now as well. I'm handling this by writing the checked items to localStorage so they carry across to page 2, 3, etc.. as well as show up as already checked when you go back to page 1. Then every time the page loads, either find and check the existing checkbox, or create a hidden input with the appropriate name and value and append it to the main form.
var selected_items = []
function add_item_to_checkbox(item) {
localStorage.setItem('selected_items', JSON.stringify(selected_items));
checkbox.on("click", add_item_to_checkbox);
bahh... Just look at my jsfiddle it's easier to read and yeah. I don't have to type JS into a textarea on stackoverflow.
Here is my javascript minus a few things that are specific to my code. I'm sure it could be improved upon but it works really well for my application.

Best Product Listing Option for Concrete5

I'm going to be creating a Concrete5 website that will feature product listings. The listing system must offer all your typical ecommerce features, minus the ability to purchase items. It's strictly for browsing purposes only.
For example:
- Browse by category
- Search products
- Listings/results page with thumbnails and brief information (title, description, price in US/CAD, manufacturer, maker, etc.)
- Products single page (with detailed information, attributes and gallery/images)
All the things you'd expect to find in a listing system.
My issue is I can't find a specific add-on for something like product listings. This leaves me thinking that it may be best to use the e-commerce add on and do my best to hide anything related to the cart/payment process. That way it could just be used for everything else it offers.
What are your thoughts on this? Is there a better option?
Thanks for the advice!
Use the page list block. It has everything you need except for searching. But, in essence, that's what your requirements call for -- listing of pages.
Create a page type for your "product". The "brief information" can be in the Content block, or you can set as attributes. You'll probably want to make some minor changes to the block's view (by creating a new template) that displays the image as you want, the proper attributes, etc. Something similar to http://www.concrete5.org/documentation/how-tos/designers/styling-the-page-list-block/
There are several adanced page list blocks in the marketplace. You might want to start with those.
Right creat Page type.
After creat Page attributes.
Add a block page_list create a template for it and filter by attributes.
You can even use ajax to filter.
http://www.weblicating.com/doku/doku.php?id=cheatsheet/#.UbR7P0BmiSp
U can find here about page_list or read documentation Concrete5.