How do you create an EditorTemplate in a Plugin for nopCommerce v2.20 - asp.net-mvc

I'm trying to create a plugin for nopCommerce v2.20 that allows the user to request a quote for goods and services by describing the requirements and attaching any relevant documents.
I have started by using http://blog.csharpwebdeveloper.com/2011/09/10/writing-a-plugin-for-nopcommerce-2-x/ as a guide, this has been very good so far. My project is almost identical to the one in the blog post so I'll only add code snippets as I think they are required, so please ask me to expand and provide details if I have left anything important out.
Now I want to add a facility to upload multiple files using uploadify and have decided based on the existing code that I should create an EditorTemplate for attachments.
My problem is I can't work out how to setup my template in a way that can be located by the MVC framework when I use the following line of code to get the template.
#Html.EditorFor(m => m.Attachment)
In my model I’m using the UIHintAttribute("Attachments") on the Attachment property to identify the template with no noticeable effect.
I have created a folder below the "Views" folder called "EditorTemplates" and added a file called "Attachments.cshtml" with the build action set to "Embedded Resource", contents below:
#model int
#using Nop.Core;
#{
var randomNumber = CommonHelper.GenerateRandomInteger();
var clientId = "download" + randomNumber;
var downloadService = EngineContext.Current.Resolve();
var download = downloadService.GetDownloadById(Model);
}
<div>This is a download control #string.Format("randomNumber = {0}, clientId = {1}, download = {2}", randomNumber, clientId, download);</div>
I intend to implement the template once I can get the MVC framework to resolve its location.
So is it possible to have an editor template in a plugin (a separate class library from the main project) and if so what do I need to do to enable the MVC framework to resolve my template location?
I'd also like to add I'm quite new to MVC, Razor, and nopCommerce, sorry in advance if I missed something obvious.
As a side, could you suggest a better title for my question as stackoverflow tells me that it appears subjective?
thanks

If you are trying to supply an editor template without pre-compilation (which is probably the best way until you get into some more advanced scenarios) you will want to set the BuildAction as "Content" - not "EmbeddedResource".
Also, make sure your editor template is in one of the following directory structures (you mentioned it was under "Views" which is incorrect):
/Views/{ControllerName}/EditorTemplates/Attachments.cshtml
/Views/Shared/EditorTemplates/Attachments.cshtml
/Areas/{AreaName}/Views/{ControllerName}/EditorTemplates/Attachments.cshtml
/Areas/{AreaName}/Views/Shared/EditorTemplates/Attachments.cshtml
If you do want to embed the templates as part of a separate library, I suggest you look at this post from Chris Van De Steeg.

Related

Swagger-Swashbuckle include xmlcomments from dependent dlls

I need to document an asp.net core web api and I m using swagger and swashbuckle.
I have looked around and I have found this link but it's old and does not work
https://github.com/domaindrivendev/Swashbuckle/issues/93
Can somebody show/point me how i can include xml comments from another dll?
thanks
There are two versions of swashbuckle:
https://github.com/domaindrivendev/Swashbuckle
https://github.com/domaindrivendev/Swashbuckle.AspNetCore
If the tags on this question are correct, your link is not to the version you are using, but still the solution offered should give you a good idea what you need to do.
You can include as many xml comments as you want with IncludeXmlComments that is still available on Swashbuckle.AspNetCore, see here:
Swashbuckle.AspNetCore.SwaggerGen/Application/SwaggerGenOptions.cs#L259
First you need to make sure that the xml comments you need are making it to the server as part of your deployment, otherwise Swashbuckle will not show what it is not there...
A solution could be to recursively loop looking for XML files and add them using the IncludeXmlComments, something like this:
public void IncludeAllXmlComments(string folder)
{
if (!string.IsNullOrEmpty(folder))
{
foreach (var name in Directory.GetFiles(folder, "*.XML", SearchOption.AllDirectories))
{
IncludeXmlComments(filePath: name);
}
}
}
This sample code is just to give you an idea, not for copy/pasta

Automatically populating default issue fields?

We are working on transitioning to Zephyr for JIRA from HP QC/QTP; but a tiny wiggle has presented itself:
When creating a new issue from a test run; the tester has to manually enter version info for the new defect, which on its own is fine, but it's an additional step, and on occasion forgotten.
What we would like then, is for the field "Affects Version/s" to be automatically filled based on either the state of the project, or the sepcific values set in fields in the test.
How can this be achieved?
Allright. You can add custom javascript to JIRA by going to JIRA Administration -> System -> User Interface -> Announcement Banner.
The easiest way is to add a tag linking to your javascript file (wherever it is, must be available to all users. Preferably on the same server as your JIRA installation or a public domain).
Example:
<script type="text/javascript" src="http://YOUR_JIRA_SERVER/includes/custom/javascript/custom.js"></script>
If you add it like above, go into your JIRA installation into the atlassian-jira/includes/ folder and add a folder called custom within which you add another folder called javascript and create a file called custom.js.
In that file, add the following code:
AJS.$(document).ready(function()
{
AJS.$(document.body).on('change', '#issuetype-field', function()
{
var issuetype = AJS.$(this).val();
if(issuetype === "Test") //Might want to change this!
{
AJS.$("#fixVersions").val(17403); //Might want to change this!
}
});
});
This will add an eventlistener to the issuetype-field input found in the create modal window in JIRA. When it changes (which it automatically does on load, then on every user select) it check its value to see if it's Test and if so changes the fixVersion input to a whatever you want to set it to (change this to match your own preferences).
Using jQuery with jira is a bit tricky, you need to use the AJS object to access the jQuery object (more information here: https://docs.atlassian.com/aui/latest/docs/applicationHeader.html).
The two parts you need to change are the actual names and values of your issuetype and your fix version (use firebug or your browsers equivalent to get this).
I've tried this and it worked well! Good luck!

MVC 4 VB Additional view data

Trying to find help for this problem has taken me to a whole new one: complete lack of ressources, books and samples vor MVC 4 in VB.NET. I am having to choose between learn by experience (and the associated feeling of banging your head against a wall) or give it up and move to C# alltogether.
No company should ship a product if they are not willing to give it the same support as its sibling pruduct. They should drop VB for MVC completely or give us the means to learn it.
With that out of the way, here's my question. This line:
#Html.EditorFor(Function(x) x.UsersData(temp).Roles(Role))
Is a nice line of code. Works wonders. But How can I add a class to it, so I can change the style on my css files?
Well, it seems that this should do the trick:
#Html.EditorFor(Function(x) x.UsersData(temp).Roles(Role), New With {.class = "users-manage-check-box"})
But guess what, it doesn't. Ever. The result is the same.
What is wrong and how can I fix it?
And to be completely honest, I did come up with a solution. One that makes me feel dirty.
Looking at the output from that code, i see that the boxes classes are "check-box".
So what I've been doing is this:
#html.Raw(Html.EditorFor(Function(x) x.UsersData(temp).Roles(Role), New With {.class = "users-manage-textbox"}).ToHtmlString.Replace("check-box", "user-manage-checkbox"))
This feels wrong. So wrong. And not only is it a sad piece of code, it introduces security risks, which I'll have to fix before my solution is out of the development phase.
Any clues on why the additional view data is not working as it should? Am I getting something wrong? Am I asking too much?
Thanks a lot!
I don't think EditorFor allows that. So you need to create a custom editor template yourself.
You can read more about creating custom templates in this blog post
Update:
Take a look at the answer for this issue from http://aspnetwebstack.codeplex.com/
This behavior is by design.
The overload that you are calling accepts an object parameter called
additionalViewData (http://msdn.microsoft.com/en-us/library/ff406462).
The default implementation of EditorFor ignores this value. You would
have to write a custom editor template to be able to access that
information.

How to dynamically generate url for image map in Oracle ApEx?

The scenario:
I have an ApEx page which pulls a record from a table. The record contains an id, the name of the chart (actually a filename) and the code for an image map as an NVARCHAR2 column called image_map.
When I render the page I have an embedded HTML region which pulls the image in using the #WORKSPACE_IMAGES#&P19_IMAGE. substitution as the src for the image.
Each chart has hot spots (defined in the image_map html markup) which point to other charts on the same ApEx page. I need to embed the:
Application ID (like &APP_ID.)
Session (like &APP_SESSION.)
My problem:
When I try to load the &APP_ID as part of the source into the database it pre-parses it and plugs in the value for the ApEx development app (e.g. 4500) instead of the actual target application (118).
Any help would be greatly appreciated.
Not a lot of feedback - guess I'm doing something atypical?
In case someone else is trying to do this, the workaround I ended up using was to have a javascript run and replace some custom replacement flags in the urls. The script is embedded in the template of the page and assigns the APEX magic fields to local variables, e.g.:
var my_app_id = '&APP_ID';
Not pretty, but it works...
Ok - I think I've left this open long enough... In the event that anyone else is trying to (mis)use apex in a similar way, it seems like the "apex way" is to use dynamic actions (which seem stable from 4.1.x) and then you can do your dynamic replace from there rather than embedding js in the page(s) themselves.
This seems to be the most maintainable, so I'll mark this as the answer - but if someone else has a better idea, I'm open to education!
I found it difficult to set a dynamic URL on a link to another page - directly - attempting to include the full URL as an individual link target doesn't work, at least in my simplistic world, I'm not an expert (as AJ said: any wisdom appreciated).
Instead, I set individual components of the url via the link, and a 'Before Header' PL/SQL process on the targeted page to combine the elements into a full url and assign it to the full url page-item:
APEX_UTIL.set_session_state(
'PG_FULL_URL',
'http...'||
v('PG_URL_COMPONENT1')||
v('PG_URL_COMPONENT2')||
'..etc..'
);
...where PG_FULL_URL is an item of Type 'Display Image', 'Based On' 'Image URL stored in Page Item Value'.
This is Apex 5.1 btw, I don't know if some of these options are new in this release.

Maintain parameter info in the request path for all pages instead of the subdomain

I seek some guidedence here ... ( I'm not sure if this is the best title )
At the moment I prepend a "server name" to the url like this:
server10.example.com
This works fine, except that I need to handle all the subdomains on the IIS and I'm not sure google are happy about jumping around from sub to sub to sub, when it seems the links to the other servers.
I'm kind a hoping for a nice way to archive this wioth asp.net mvc.
Most pages are related to a "server" ... there are however a few info pages, contact, home that dont really need a valid "server" name ... but could just be "na" for not available, but the name need to be maintained, if there is already a selected server, when a user are keeps browsing the site. This needs to be as transparent as possible when I need to create the links to the diffenrent pages.
I could extend the Html Action() extensien to automatically add the selected "server" from the previusly request to the page.
In the format:
/{serverParameter}/{controller}/{action}/{parameterInfo}
And if no server is selected, just add "na" as the {server} placeholder.
I'm not sure if more information is needed, but please let me know if ...
I tired of extracting the selected server from the domain part and the other way also seems better, I just can't think of a good way to structure this ...
Updated
90% of all the pages are about a server that the user select at some point. Could be server10, server9, server20 ... just a name. I want to maintain that information across all pages, after the users has selected it or else I just want it to be f.ex: "empty".
I mostly looking for an easy way of doing this or an alternative ... atm I'm prepending the serverParamter to the url so it ends up being: "serverParameter.example.com".
I want to end up with something like
http://example.com/{server}/{controller}/{action}
instread of
http://{server}.example.com/{controller}/{action}
If I understand your question correctly, you just wish to group different collections of content together above the controller/action level. If that's the case, have you considered using ASP.NET MVC areas?
Just right-click on your project, and choose Add -> Area.... Give it a name (what you're calling "server"), and then you can add content, your own controllers, actions, etc. Under this area. You will automatically be able to access it via /AreaName/Controller/Action/etc.
I went with the already impemented routing in ASP.NET MVC.
{server}/{controller}/{action}
When creating the links it takes the set value for {server} and places the value when generating URL's, so I only need to supply controller and action in the #Html.Action helper method ... this could not have been more easy.
I'm not sure why I did not think about this. One just gotta love routing.

Resources