Showing posts with label NuGet. Show all posts
Showing posts with label NuGet. Show all posts

Saturday, June 7, 2014

Step By Step How to create a custom NuGet Package

       By Carmel Shvartzman
In this tutorial we'll learn How to create a NuGet Package , containing a template with the Controllers, Views, Images, CSS & Scripts that you need in your Asp.Net MVC applications. We'll save our package in intranet or local file system, and use it every time we create a new project.
For this tutorial, we'll  create an MVC application as Template to future projects, and save it as a NuGet Package.
Then, we'll create an empty MVC application, and we will use that NuGet package as a bootstrap for the new project , showing as follows:




First thing, browse to the Visual Studio Gallery at MSDN & update your NuGet Package Manager:


Next, you'll need a free tool called NuGet Package Explorer , at CodePlex :


Now, build the MVC application template that you want to save. For example, create an empty MVC app & add a View just as:



And also a Controller:


1) EVERY code file MUST be appended " .pp  "
2) in the code, the namespace name MUST be replaced with a generic " $rootnamespace$ " 


Now open the NuGet Explorer that you downloaded , & create a New package:

Edit the package taking care of setting Title, Author, Description, Language, Tags & Summary :


Edit whatever Dependencies the package should have :



Then add a Content folder:


Paste inside it all files & folders from your application, that you want to be part of your template :


Check whether you got all you need for your package:


Then add the DLLs from your template to the package:


First set the Framework version you want:


Copy-paste the DLLs :


Save the Package :


And Analyze it for errors:





Now go to the NEW project where you want to IMPORT the NuGet Package. Open the NuGet Manager at Settings & tell it WHERE to look up for your local Packages:


Finally, open the NuGet Manager:

Find your Package at the FOLDER WHERE you put it:

Take a look where go the Title, Summary etc.
Install your custom NuGet Package :

Check whether you got the whole template:





That's all!! 
In this tutorial we've learn how to create a NuGet Package hosted in the local file system, containing a template with the Controllers, Views, Images, CSS & Scripts that you need in your Asp.Net MVC applications. 

Happy programming.....


כתב: כרמל שוורצמן

Friday, June 6, 2014

Step By Step How to create a JQuery UI Dialog widget in 10 minutes

        By Carmel Shvartzman

In this tutorial we'll learn how to use the JQuery UI Dialog widget  in 10 minutes. The jQuery UI is a set of user interface widgets, interactions, and themes built on top of the jQuery JavaScript Library.
We'll customize the JQuery UI Dialog so that it's located in the MIDDLE of the web page, will remain 2 seconds on the screen, and then will disappear. The custom Dialog will also contain a "Close"  button to hide itself.
We'll want to add to our MVC site the jQuery Dialog , showing as follows:




For the sake of using JQuery UI Widgets, like Accordion, Tabs, Portlets, Dialogs, and so on, we'll need to import a JQuery UI Theme, the jquery-ui.js and jquery-ui.css files. (and of course you'll need also a reference to the basic jquery.js file).

The present section is a sub-tutorial about importing the JQuery UI to our app: you can delay it if you already have done it, or you can see the complete step by step  in a former tutorial.

This is the BEGIN of the  sub-tutorial section: -----------------------------------------------------
---------------------------------------------------------------------------------------------------

First of all, we need to download the Theme from the JQuery UI site, so browse to the site and go to the "Themes" tab:


Select from the "Gallery" the theme you like the most, and download it. I choose the "Le-Frog":



After you download it, extract all from the .ZIP file :


We'll use some of these files. But first , we need to update the javascript jQuery files in our project, because the files which comes with Visual Studio will be obsolete. Open the NuGet utility:


Make a search for the JQuery package and install it:


Do the same for the JQuery UI package:


Now open the Theme's folder we downloaded and copy the entire theme which is inside the "development-bundle" folder:



Paste the folder inside the "themes" folder inside your project:


It will show as follows:


We'll make use of the .CSS file jquery-ui.css. Open the BundleConfig file:



Take a look at these ScriptBundles, because we'll use them inside our app:



Replace the "base" folder by the "le-frog" folder, and add the jquery-ui.css file to the script:


Next, we'll call the bundles from the _Layout file:


Locate the Render "jquery" section and cut it:


Locate the render at the <head> section:


Paste there the "jquery" section , and add the "jqueryui" bundle:



We're done with the javascript and the style we'll need.
Now we'll add the Dialog widget to the Index View. Create a new View:


This is the END of the  sub-tutorial section --------------------------------------------------------
---------------------------------------------------------------------------------------------------



To get the code of the Dialog, browse to the "Development" tab at the JQUERY UI site, and select  the "Effect" demo:




Then go to the "View source", because we'll customize the STYLE, SCRIPT and DIV sections of the Widget to make our own Dialog:






Put  an <script> tag inside your Index file, and code the following functions:


Here we have the following functions:
1) a hide() : to make invisible the Dialog;
2) a #btnOpenDialog : when the button is pressed, SHOW the Dialog;
3) a #btnCloseDialog : when the "Close" button is clicked, hide() the Dialog;
4) the fnShow() : show the Dialog using the "puff" effect during 2 secs, and THEN call a CALLBACK function named:
5) callback() : WAIT 2 secs, and then hide the Dialog using the "puff" effect during 2 secs.

<script>
    $(function () {
        $("#effect").hide();

        $("#btnOpenDialog").click(function () {
            fnShow();
        });

        $("#btnCloseDialog").click(function () {
            $("#effect").hide(500);
        });

        function fnShow() {
            $("#effect").show("puff", 2000, callback);
        }

        function callback() {
            setTimeout(function () {
                $("#effect").effect("puff", {}, 2000);
            }, 2000);
        };
     
    })</script>

Copy the Dialog <div> markup:


And paste it somewhere inside our Index file, with some customization and the adding of a "Close" button:



<div class="toggler" style="">
    <div id="effect" class="ui-widget-content ui-corner-all">
        <div>
            <div style="float: right;">
                <a href="#" id="btnCloseDialog" class="ui-state-default ui-corner-all">Close</a>
            </div>
            <h3 class="ui-widget-header ui-corner-all">Effect</h3>
        </div>
        <p>
            Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede.
            Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
        </p>
    </div>
</div>

Also, add a button to open the dialog from the Client side:



<div style="width: 100%;">
    <a href="#" id="btnOpenDialog" class="ui-state-default ui-corner-all">Press to open a Dialog
    </a>
</div>

Last but not least, we need to customize the style of the Dialog, so copy the <style> CSS from the JQuery UI site:


 Again, we'll use the JQuery UI source as a bootstrap, but we'll customize it in order to make the Dialog appear IN THE MIDDLE OF THE WEB PAGE:



<style>
    .toggler {
        width: 500px;
        height: 200px;
        position: absolute;
        left: 600px;
        top: 350px;
    }
    #btnOpenDialog {
        position: fixed;
        left: 50%;
        margin-left: -100px;
        padding: 5px 5px;
        text-decoration: none;
        font: 900 12px georgia;
        color: #FFF;
    }
    #effect {
        width: 240px;
        height: 135px;
        position: fixed;
        top: 50%;
        left: 50%;
        margin-top: -50px;
        margin-left: -100px;
    }

    #effect h3 {
        margin: 0;
        padding: 0.4em;
        text-align: center;
    }
    .ui-effects-transfer {
        border: 2px dotted gray;
    }
</style>

Here, #effect is the name of the Dialog, and #btnOpenDialog is the button which opens it. As you see, i added a CSS code to position the JQuery UI Dialog IN THE MIDDLE of the web page:

      position: fixed;
        top: 50%;
        left: 50%;
        margin-top: -50px;
        margin-left: -100px;
What i'm telling here is something like this: "position yourself in the MIDDLE of the web page, and then move a bit up and left, to remain in the middle".

Finally, let's run the application to see the Dialog in action. The Button when clicked will open the Dialog:





The Dialog remains opened for only 2 seconds:







...and then it vanishes automatically:







Or can be closed by the user:




That's all!! 
In this tutorial we've learn how to use the JQuery UI Dialog widget in 10 minutes.  

Happy programming.....


כתב: כרמל שוורצמן