How to put files and folders on umbraco webpage - umbraco7

I am using Umbraco for the first time. I want to put folders and sub folders and pdf files on my webpage for a "Public Access Documents page". Something like this :
Can someone please tell me how to do this ??

You could create a media folder structure called documents then a child folder called meeting minutes with children folders of the year. To get the document paths you would need code something like this (10 would be the id of your Documents node - get this from the URL in the backend):
#foreach (var documentType in Umbraco.TypedMedia(10).Children)
{
foreach (var year in documentType.Children)
{
foreach (var document in year.Children)
{
#document.Url
}
}
}
In terms of the styling and how it looks there are frameworks like bootstrap which will give you a base on how it's looks on the frontend.

Related

Spatie media library getMedia() not returning all images

I am receiving multiple images in base64 from rich text editor. My idea was to upload all the images and replace base64 img src in article content with newly created image path. I am using spatie media library and Laravel.
foreach ($data['images'] as $image) {
$article->addMediaFromBase64($image)->toMediaCollection('article-images');
$mediaItems = $article->getMedia('article-images');
$article->content = str_replace($image, $mediaItems[count($mediaItems) - 1]->getFullUrl(), $article->content);
$article->save();
}
The problem I have is that $article->getMedia('article-images') always returns only the first created image and the count is always one. So what ends up happening is no matter how many images I upload it will replace all their src tags with the url of the first image.
This is the final solution I went with. The relationship was probably cached after the first image upload and that's probably why I was always getting the first image. After loading media relation on the model, I was able to retrieve all images in the collection properly.
foreach ($data['images'] as $image) {
$article->addMediaFromBase64($image)->toMediaCollection('article-images');
$mediaItems = $article->load('media')->getMedia('article-images');
$article->content = str_replace($image, $mediaItems[count($mediaItems) - 1]->getFullUrl(), $article->content);
}

Download database file attachments by their real names

I can't figure out how to get a database file attachment, to be downloaded with is real file name.
My model have many file attachements (many attachOne) and there is no problem to get link to them with
{{ model.myfile.filename }}
What I want to do is to get those files downloaded with their real file name.
I try to define an ajax event handler in my layout like so :
function onDonwload()
{
$path = post('path');
$name = post('name');
// Storage::exists('uploads/public/5ce/28c/3aa/5ce27c3aae590316657518.pdf'); => OK
// Storage::exists($path); =>OK
$path = storage_path().'/app/'. $path;
return Response::download( $path, $name);
}
and
<button data-request="onDonwload"
data-request-data="path: 'uploads/public/5ce/28c/3aa/5ce27c3aae590316657518.pdf', name: 'my real name">
Download
</button>
No missing file error, but get the browser to freeze with an alert that say "A webpage slow down your browser, what do you want to do?".
Did I miss an important point?
You should add separate page for downloading files, Ajax can not help you to download file ( may be it can but process is little complex and long)
create page with /file-download/:id here you can specify any url wit param :id and give it name file-download you can give any name you like for demo i used this name.
In that Page Html section will be Blank and in Page's code section add this code. here you can also check additional security check like user is logged in or not file is of related user or not. for now i am just checking file is related to particular Modal or not.
function onStart() {
$fileId = $this->param('id');
$file = \System\Models\File::find($fileId);
// for security please check attachment_type == your model with namespace
// only then lat use download file other wise user can download all the files by just passing id
if($file && $file->attachment_type == 'Backend\Models\User') { // here add your relation model name space for comparison
$file->output('attachment');
}
else {
echo "Unauthorised.";
}
exit();
}
Generating links, please replace page name with page you created.
<a href="{{ 'file-download'|page({'id': model.myfile.id}) }}" >{{ model.myfile.filename }}</a>
Now, when you click on link file should be downloaded with its original name, and for invalid file id it should show message Unauthorised..
if any doubts please comment.

Shopify AJAX - update total price of line item

I have found into on how to change your quantity of items via AJAX on the cart page, and I have also found how to update the cart total via AJAX.
What I have not found is how to update the total line item price for each line item as you increase or decrease the quantity.
Here is the code I have thus far (not working) ...
jQuery.getJSON('/cart.js', function(cart) { $('#line-total-{{ item.id }}').html(Shopify.formatMoney(item.line_price).replace('$','£'))})
Any tips on what is wrong with my code?
Also this is within an onclick on a button if that helps.
Your code includes:
jQuery.getJSON('/cart.js', function(cart) {
$('#line-total-{{ item.id }}').html(Shopify.formatMoney(item.line_price).replace('$','£'))})
The above will not work, as the Liquid-based {{ item.id }} will get dropped once into the page, never to change afterwards. (Most likely, the above code was included in a place where there was no Liquid variable named item in scope, so the rendered Javascript would have simply read $('#line-total-')
You'll need to use the Javascript cart object that is being given to your function. For example:
jQuery.getJSON('/cart.js', function(cart) {
for(var i=0; i<cart.items.length; i++){
var item = cart.items[i];
var price_element = $('#line-total-' + item.id)
price_element.html(Shopify.formatMoney(item.line_price).replace('$','£'))})
}
})
Hope this helps!
You're getting "cart" back from /cart.js but you're not reading any of its data.
You will need to read through the cart object (which will be represented as a shopify "Cart" object) in your javascript. I see you're trying to get the "item.id" and "item.line_price", but there is not relationship to the item and the cart object. You also cannot use liquid at this point as this will already be rendered to the client...
You likely need to do something similar to:
jQuery.getJSON('/cart.js', function(cart) { cart.items.each($('#line-total-'+this.id).html(Shopify.formatMoney(this.line_price).replace('$','£')););});

2sxc | SQL Datasource - LINQ Filter Query

I have a SQL Datasource setup to get all documents of a certain extension from the standard DNN 'Files' table but I want to add an extra level of specification on what category of file to display but not sure how best to go about it. See my current SQL Datasource code below:
#using ToSic.Eav.DataSources
#functions
{
// Default data initialization - should be the place to write data-retrieval code
// In the future when routing & pipelines are fully implemented, this will usually be an external configuration-only system
// For now, it's done in a normal event, which is automatically called by the razor host in 2SexyContent
public override void CustomizeData()
{
var source = CreateSource<SqlDataSource>();
// source.TitleField = "EntityTitle"; // not necessary, default
// source.EntityIdField = "EntityId"; // not necessary, default
// source.ConnectionString = "..."; // not necessary, we're using the ConnectionStringName on the next line
source.ConnectionStringName = Content.ConnectionName;
// Special note: I'm not selecting * from the DB, because I'm activating JSON and want to be sure that no secret data goes out
source.SelectCommand = "Select Top 10 FileId as EntityId, FileName as EntityTitle, PublishedVersion, UniqueId, FileName, Size as Size, Extension as Extension, CreatedOnDate as Date, Folder as Folder FROM Files WHERE PortalId = #PortalId AND Extension = 'docx' OR Extension = 'xlsx' OR Extension = 'pdf'";
source.Configuration.Add("#PortalId", Dnn.Portal.PortalId.ToString());
Data.In.Add("FileList", source.Out["Default"]);
// enable publishing
Data.Publish.Enabled = true;
Data.Publish.Streams = "Default,FileList";
}
}
I want to sync the 2sxc Categories entity with DNN's Tab/Page Taxonomy Tags/Categories so as to allow a user to select a DNN Tag on Page setup which (if synced with the 2sxc Categories entity) will allow me to assign a specific doc/excel/pdf file (already connected via 2sxc iCache to a 2sxc Category) to an app based on the SQL Datasource which connects via joining the taxonomy_terms table with the content items table and in turn with the content item tags table which connects with the DNN tabs table.
How can I correct my LINQ/Razor code below to filter my Categories to only display files with the exact 'Services' Category assigned to them. I will use this filter to sync with the Taxonomy Tag 'Services' (exact match) which I want to link to the 2sxc Category (which has an uploaded Adam file already connected via 2sxc iCache) with DNN Taxonomy term 'Services'?
#foreach (var file in AsDynamic(Data.In["FileList"]).Where(i =>
(i.Category as List<dynamic>).Any(c => c.EntityId == FileList.EntityId)))
{
<li>#file.FileName</li>
}
I have looked in detail at the wiki notes on https://github.com/2sic/2sxc/wiki/DotNet-Query-Linq and I am stuck on getting the correct syntax for the category filter with using a foreach with the SQL Datasource template.
Cheers...
I believe we have solved this by mail already.
One minor recommendation: if you use DnnSqlDataSource instead of the SqlDataSource you already have the correct connection string for your current DNN. See also http://2sxc.org/en/docs/Feature/feature/4670 as well as https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All
Yes, the filter I needed was as you provided below:
#using ToSic.SexyContent
#{
// all QandA items
var all = AsDynamic(App.Data["QandA"].List);
// the filter value, can be set in template
// but usually you would either get it from url with Request["urlparam"]
// or from a setting in the view, using Content.Category
var currentCat = "Business";
// filter, find any which have the current category
var filtered = all
.Where(p => (p.Categories as List<DynamicEntity>).Any(c => AsDynamic(c).Name == currentCat));
}
<div class="clearfix">
#foreach (var q in filtered)
{
<div class="sc-element" data-tags="#String.Join(",", ((List<DynamicEntity>)q.Categories).Select(a => AsDynamic(a).EntityId))">
#Edit.Toolbar(Content)
<div class="col-md-12">
<div class="">
<a href="#q.Link" class="">
<span class="">#q.Link</span>
</a>
<p>#q.Title</p>
</div>
</div>
</div>
}
</div>
Thanks again!

Umbraco Beginning Razor - list all news items

Hi I have a node events and have 6 types 'eventItem' which are children. On my homepage I want to list all nodes of type eventItem and list the eventDate.
Thanks
Using razor you could do something like the following:
#{
dynamic eventFolder = Library.NodeById(1234);
<ul>
#foreach (var event in eventFolder.Children)
{
<li>#event.eventDate.ToShortDateString() - #event.Name</li>
}
</ul>
}
Obviously, replace "1234" with the actual Id of the event folder and then place the razor script inside a macro and put the macro on your home page's template and you should be good to go.

Resources