Friday, December 4, 2015

CRUD OPERATIONS USING SHAREPOINT 2013 RESTAPI & ANGULARJS (PART2)

As we discussed in Part1 we talked about why we going to use Angularjs with Sharepoint then we decided to explain our topic by demo
i'm an employee in company and need to request vacation so i will log into sharepoint with my account and fill form then send vacation request , i need to see process flow where it located now or who is responsible for take an action for my task now, in other side if i'm employee who has this task now i need to respond on this task. 

Check Final result of  Demo  that we will do it now.

NO PAGE LOADING ANY MORE :) 

now we will start with first point which is  "Build Angularjs Structure"  , actually we have many type of structure when we start to use Angularjs but i prefer to use following structure but feel free to use your own :

Example :

  • Demo "folder under Styles SharePoint mapped folder"
    • Employee  "folder container"
      • controllers "folder container"
        • AddEmployeeController.js  "controller file"
      • services "folder container" 
        • EmployeeServices.js "services file"
    • App.js "main angularjs file"
    • Directives.js "common directive file"
    • Messages.js "file contain all common messages you will use in your project"
    • services  "folder contain most common service over project"
      • utility.js " common service file can use over project"
  • Demo "folder under Layouts SharePoint mapped file"
    • add.html  "view model"
and now we will start our demo , open your visual studio :D :D 

we will create 2 projects one for common functions and other specific for employee functionality.

first step we will create general services that we will use it over sharepoint

1- create empty SharePoint project "Demo.CommonUI" as farm solution


2- create folder "Demo" under STYLES mapped SharePoint folder (Templates > Layouts > Styles)




3- create folder "Vendor" under demo folder
we will add add library will be used in our demo under this folder.

add Angularjs framework files  under this folder you can download it through this link ,

actually i will use CDN links in my demo to save time., here is some prerequisite  libraries we will use in our project :
  • jquery
  • Angularjs : for angularjs functionality
  • ng-table : for draw tables with full functionality (feel free to use your own library)
  • toaster : for show notification after api response.
  • loader : for show loader if request required time.
  • UIBootstrap : for boot strap controls
my current vendor now will contain only files for "loader" and  i will use CDN for other libraries 
so project now will look like:



4- create some common files under "Demo" folder   :

  •  create "app.js" :
    • in code below we will handle routing of views and it's mapped controllers also we will add configuration for loader and inject all libraries that we will use in our project


  • create "Directives.js":
    • we will use it to create our own directives to use it in views, in code below i will use my custom datepicker and validation to validate FromDate & ToDate when employee submit vacation 

  • create "Messages.js":
    • we will use it centralize out used messages accross system

  • create folder "services":
    • create "baseSvc.js"
      • this file one of the most important files in our project here we will add all method GET,POST  that will call SharePoint RestApi.

    • create "UtilityService.js"
      • if you have any common function you can add it in utility.




5- now we need to create our views for all CRUD operations.
  • Add "Layouts" SharePoint mapped folder
    • create folder "EmployeeVacation" under "Demo.commonUI" folder add following files :
      • create "add.html" that will appear when employee need to request vacation
      • create "details.html" to show details about request.
      • create "MyRequests.html" to show all requests created by logged in user.

      • create "MyTasks.html" to show all tasks assigned to logged in user


      • create "process.html" to show current task status



6 - At last we are going to create our page layout 

  • create folder "PageLayouts"
    • under folder create module "PageLayouts"
      • delete sample.txt
      • add text file "DemoManagementPageLayout.aspx" then add magic code below :
      • update file "Elements.xml" with code below :









Finally we finished CommonUI Structure, congratulations :D .


















No comments:

Post a Comment