गुरुवार, फेब्रुवारी २३, २०१२

Ruby Require vs Load

ही पोस्ट दिग्गज हितेश रावल यांच्या personal blog Hello World मधून घेतली आहे.

Load व Require methods चा वापर अतिरिक्त source files चा समावेश करण्याकरिता होतो. या दोन्ही methods चा वापर तेव्हा केला जातो जेव्हा तुम्ही load करत असलेल्या library चे definition वेगळ्या file मध्ये केले गेलेले असते. हे दोन्ही methods Ruby च्या Kernel module मध्ये define केलेले आहेत.

Require: Require method तुम्हाला library load करून देतं आणि त्याला परत load होण्यापास्न रोखतं. जर तुम्ही तीच library परत load करायचा प्रयत्न केला तर Require method 'false' return करतं. या वरून आपल्याला कळते कि Require method एखादी library load झाली आहे कि नाही याची पाहणी करतं. तुम्हाला त्या library file च्या नावाचे '.rb' extension चा उल्लेख करायची गरज नाही.
उदाहरणार्थ,
'boot.rb' चा code:
require 'rubygems'

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])

Load: Load method व Require method मध्ये बरेचसे साम्य आहे, पण Load हा एखादी library load झाली आहे कि नाही याची पाहणी करत नाही. याचा वापर तेव्हाच केला गेला पाहिजे जेव्हा module मध्ये वारंवार बदल केले जात अस्तील आणि आपल्याला एखादी library प्रत्येक वेळेला load करायची गरज पडत असेल. Load मध्ये तुम्हाला file extension चा उल्लेख करावा लागेल.
load(File.dirname(__FILE__) + "/schema.rb")

The original post can be viewed on Hitesh Rawal's personal blog Hello World! as Ruby Require vs Load

मंगळवार, फेब्रुवारी ०७, २०१२

Software testing: मुळ परिचय (Software testing: A Basic Intro)

जेव्हा आपण software testing चा विचार करतो तेव्हा २ प्रश्न आपल्या समोर उभे रहातात. Software म्हणजे  काय? आणि testing म्हणजे काय?

Software काय आहे? : Software हे एक operating information आहे जे आपले प्रत्येक दिवसाचे काम सुरळीत करते. आणि Testing म्हणजे एखाद्या system ला तपासणे व त्याचे अपेक्षित निष्पन्न व्यवस्थित पार पाडले जात आहे का? हे पडताळणे. System जे अपेक्षित आहे तेच करतय का? Software आणि Testing चं वरील वर्णन साधं आहे, अतिशय साधं. हे अजुन चांगल्या शब्दांमध्ये प्रचलित करू शकतो जे नामांकित शब्द्कोशातुन जमा केलेत.
Software: Computer Software किंवा Software म्हणजे computer programmes व संबंधित data चा संग्रह असतो, जे काही नियम computer ला आखून देत आणि सांगत की काय कधी करायच. हे programs तुमच्या computer च्या hard drives मध्ये जतन केले जातात.

Testing: टेस्टिंग ही अशी एक प्रोसेस आहे ज्यामध्ये एखाद्या item च्या features चे मुल्यांकन केले जाते व सध्याच्या आणि अपेक्षित परिणाम या मधला फरक शोधला जातो
मग जर तुम्ही दोन्ही terms एकत्र केले तर software testing बनते.
तर Software Testing म्हणजे Software ची नीट चाचणी करणे आणि ते अपेक्षितपणे चालत आहे का हे तपासून पाहणे. Software जसे पाहिजे तसे चालत आहे का?

Software testing: Software testing हे एक अशी process आहे ज्यामध्ये software ची सुरुवाती पासून शेवत पर्यंत workflow आणि functionality check केली जाते. ह्या मध्ये सर्वात जास्त software ची कमतरता तपासली  जाते ज्याला bugs असेही  म्हणतात. तसे बघितले तर functional किंवा non-functional testing द्वारे system break करण्याचा पूर्ण प्रयत्न केला जातो. ह्यालाच software ची quality वाढवण्याची तार्हा समजली जाते.

Objectives of testing:
  1. Software ची functionality सुरुवातीपासून शेवटपर्यंत check करायला.
  2. जसे चालायला पाहिजे तसे चलते का?
  3. तुटलेल्या links किंवा workflows शोधायला.
  4. System मधले bugs शोधायला.
  5. Positive तसेच negative ways शोधायला.
मग मनात अजुन एक प्रश्न येतो की कोण सांगत की software नी नक्की कसे चालायला पाहिजे? किंवा कुठल्या artifacts च्या विरुध software check करायला हवे? कुठल्या components च्या आधारे आपण म़त ठेवू शकतो की ते पाहिजे तसे चालत आहे?
ह्याचे उत्तर असे की baseline requirement दस्तावेज. आणि हे requirement दस्तावेज customer किंवा client कडून दिले जातात. जेव्हा हे दस्तावेज customer आपल्या service provider ला देतो तेव्हा ते draft format मध्ये असतात. हे analyze आणि review केल्या नंतर जर service provider company ला काही requirement बदलाविशी वाटली किंवा नाकबुल किंवा काही कमीपण, तर customer ला सांगितले जाते. अजुन काही विचाराननंतर requirement पक्की केली जाते. ह्याच पक्क्या केलेल्या requirement ला Base line Requirements असे बोलतात.

Characteristics of Requirement:
  1. स्पष्ट: काय, कधी, कसे असले अगदी स्पष्ट असले पाहिजे.
  2. पूर्ण: workflow ची पूर्ण cycle असायला पाहिजे. म्हणजेच त्याची सुरुवात तसेच शेवट दोन्ही असायला पाहिजेत.
  3. मोजता येण्यासारखे: एखाद्याला ते मोजण्यासारखे असावेत जसे बैंकचे खाते क्रमांक हयात फक्त अंक असले पाहिजेत आणि त्याना अक्षराने sort करता नाही आले पाहिजे.
  4. Test करता येण्यासारखे: अशा requirements ची testing करता येणे शक्य झाले पाहिजे. उदाहरनार्थ software ची testing OS वर, जे अजुनही आले नाही!!!  ह्यालाच future requirements असेही बोलतात आणि हे पूर्ण नाही करू शकत. म्हणून हे test plan च्या out of scope section मध्ये येते.
  5. Not conflicting: Two requirements परस्परविरोधी असू नयेत.
Product or Project Categories:
एखाद्या product आणि project ची criticality त्याच्या targeted आणि त्याचा वापर करणारया वर आधारित असता म्हणजेच कोणत्या लोकांचा गट आणि हे software त्याच्यावर काय परिणाम करणार आहे. एखाद्या software ची Product or Project समजुन जेव्हा testing केली जाते तेव्हा tester ला module च्या काही parts वर जोर द्यावा लागतो. ह्यालाच आपण categorized करू शकतो:
  1. Life Affecting software: उधारण : Medical Domain - जर कोंटा Software Medical Domain किवंह Healthcare domain करीता बनवण्यात आला आहे तर त्याचा effect प्रत्यक्ष किंवा अप्रत्यक्षपणे end users वर पडतो. म्हणून, अशा software चा अचूकपणा, गति आणि स्पष्टता यावर जास्त जोर देला जातो. म्हणून असे softwares मध्ये fail नाही झाले पाहिजेत.
  2. Money Affecting software : कोणतीही Share marketing sites, banking sites किवंह transactional related sites जे प्रत्यक्ष किंवा अप्रत्यक्षपणे आपल्या targeted customer च्या financial life ला affect करतात.
  3. Simulated testing : Space research किंवा असेच काही simulation करीता तयार करण्यात आलेले Software किंवा products(NASA मध्ये वापरण्यात येणारे Software).
  4. Others : इतर सर्व Software ह्या category मध्ये नामांकित करता येतात.
माझ्या पुढच्या post मध्ये मी software requirements , त्याचे प्रकार आणि अजुन काही testing च्या माहित बद्दल बोलेन. तो पर्यंत आनंदाने वाचा...!!!



Software testing: A Basic Intro


When we talk about the software testing, the word itself has two good questions: What is software? & what is testing?

So what is software? A Software is operating information used by computer to automate & easy going our day to day life. What is testing: Testing is to check any system & its desired expectations whether they are fulfilled or not. Is it doing what it is supposed to do? The above description for software & testing is very basic, just to keep simple. It can be defined in good words, collected from good dictionaries:

Software: Computer software, or just software, is a collection of computer programs and related data that provides the instructions for telling a computer what to do and how to do it. These programs are stored in hard drives of your computer.

Testing: Testing is the process of analyzing an item to detect the differences between existing and required conditions and to evaluate its features.
So if we combine the two terms, then it becomes software testing.
So software testing is test the software and check whether it works as expected or not. Is the software doing what it is supposed to do?

Software testing: Software testing is the process of checking the software’s end to end workflows and functionalities. It more about finding out the discrepancy in the software which is known as bugs.
It is more about breaking the system at some point, being functional or non functional. It is also known as an art of improving the quality of the software build.

Objectives of testing:
  1. To check s/w for its end to end functionality.
  2. Is it working what it is supposed to do?
  3. To find out the broken links or broken workflows.
  4. To find out the bugs in the system.
  5. To check it in positive as well as negative ways.
So, another question comes in mind, who decides that what should software do? Or against what artifacts we should check the software? What are the components on which we can decide that it working as desired?
Answer to all the questions is Baseline requirement docs. And these requirement docs are provided by our customer or by clients. When a customer provides a requirement doc to its service provider, it is in draft format. After analyzing them and reviewing them, if the service provider company founds any requirements to be changed or contradictory or any discrepancy, is reported to customer. After few more rounds of discussions, the requirements are finalized. These finalized requirements are known as Base line Requirements. Characteristics of Requirement:
  1. Clear: Should be very clear that what, when, how is required.
  2. Complete: There should be complete cycle of any workflow. It should have some start point as well as end point.
  3. Measureable: One should be able to measure them like Account number in a bank can only be numeric values and cannot be sorted alphabetically.
  4. Testable: Testing of these requirements should be possible. Eg. Testing the s/w on an OS, which is not launched yet!!. These are also known as future requirements and cannot be fulfilled. So it comes under Out of Scope section in Test Plan Document.
  5. Not conflicting: Two requirements should not be conflicting.

Product or Project Categories:
The criticality of any product or project can be decided by the targeted end user i.e. who is group of end user and how this software is going to affect them. While testing any software as Product or Project, tester needs to emphasis on some part or module of the software. This can categorized as: 
  1. Life Affecting software: Eg Medical domain. If any software is build in medical domain or healthcare domain, then directly or indirectly, life of the end user will be affected. So the accuracy, speed, clarity in the results is more emphasized. Also, the failure of these s/w is not accepted.
  2. Money Affecting software: Any Share marketing sites, banking sites, or other transactional related sites, which will directly or indirectly affect the finances of the targeted customer.
  3. Simulated testing: Software or products built for Space research, or any such kind of simulation. (S/w used by NASA)
  4. Others: rest all the s/w can be classified in this category.

In the next post I will talk more on software requirements, its types and more about the testing
Till that Happy Reading….:) !!!

PMP certified कसे बनायचे! (How to become a certified PMP!)

हा पोस्ट मनीष अ. निहाल यांच्या diary मधून घेतला आहे.

PMP काय आहे?
PMP हे जगातील प्रसिद्ध Project Management institute चे Project Management certification आहे. जवळ जवळ ३०,००० certified PMPs भारतात आहेत आणि market मध्ये अजुन लोकांना मागाणी आहे. आज technological industry मध्ये हे सर्वात जास्त pay करणारे certification आहे.
पहा Highest Paying Certification आणि Project Management Professional PMP Salary.

मान्यता :
PMP ला apply करण्यासाठी, तुमच्याकडे :
  • ४ वर्षांची degree आणि कमीतकमी ३ वर्षांचा project management चा experience, ४,५०० तासांचा leading आणि project directing आणि ३५ तासांचा project management चा अभ्यास.

  • किंवा

  • द्वितीय diploma ज्याबरोबर कमीतकमी ५ वर्षांचा project management चा experience, ज्या बरोबर ७,५०० तासांचा leading आणि project directing आणि ३५ तासांचा project management चा अभ्यास.

कृपया पहा Project Management Professional PMP

पुढे काय?
मी सल्ला करेन की तुम्ही PMI membership घेउन सुरुवात करा आणि तुमच्या जवळच्या PMI Chapter. उदाहरनार्थ जर तुम्ही मुम्बई मध्ये स्थायिक असाल तर तुम्ही PMI ची membership घ्या आणि नंतर PMI Mumbai Chapter मध्ये membership घेऊ शकता. ते म्हणतात ना, Show me a man's companions, and I will tell you what the man is. Project Manager बनायला अजुन काय चांगला पर्याय असेल ह्यापेक्षा.
ह्याचे खुपसारे फायदे आहेत जसे, PMI member असल्यामुले तुम्हाला परीक्षांच्या fees मध्ये discount मिलायला सुरुवात होते आणि online साहित्य आणि PMI online communities of practice चा access पण मिळतो. Mumbai सारखे Local chapters, members ना libraries and mentor programmes असे resources उपलब्ध करून देतात.
जर तुम्ही ३५ तासांची project management training आधीच्या अभ्यासक्रमात नसेल घेतली तर तुम्ही कुठल्याही PMI registered education देणारयांकडून, ३५ तासांची project management education (वर सांगितल्याप्रमाणे PMI च्या परिक्षेसाठी मान्यता मिळवन्यासाठी गरजेचे आहे). काही स्थानिक chapters जसे PMI mumbai chapter हीच training त्यांच्या members ना discounted मुल्यांमध्ये देतात. माझ्या माहितीप्रमाणे PMI REP fees १०,००० ते १५,००० च्या दरम्यान असते.
PMBOK (Project Management Body of Knowledge), हा फक्त ४ दिवसांचा training programme आहे आणि जास्त समजुन घेण्यासाठी, मी सल्ला देइन की तुम्ही PMBOK चा अभ्यास हा programme attend करायच्या आधीच करून घ्या.
PMBOK च्या व्यतिरिक्त मी सल्ला करेन की तुम्ही
  1. The PMP Exam: How to Pass on Your First Try, Fourth Edition by Andy Crowe
  2. PMP Exam Prep, Seventh Edition: by Rita Mulcahy
हे ही पहा.

सध्या PMP परीक्षा ४ थ्या edition वर आधारित आहे.

Applying for exam
वरील training च्या शेवटच्या तासात समजावले जाते की PMP exam चा application form कसा भरायचा. काही applications randomly उचलले जातात audit साठी, ज्यासाठी तुम्हाला application forms च्या hard copies भराव्या लागतात ज्याबरोबर तुमच्या स्वाक्षरीबरोबर references द्यावे लागतात.
ही परीक्षा online असते आणि ह्या prometric centers मध्ये घेतल्या जातात.

Other
Online खुप सारे groups आहेत ज्यामुले तुम्हाला अभ्यासात मदत होइल. PMP अभ्यासकरता शुभेच्छा


How to become a certified PMP!


This post is taken from the diary of Mr. Manish A. Nihal.

What is PMP?
PMP is a globally recognized project management certification from the Project Management institute. There are around 30,000 certified PMPs in India and the market demand is for more!. It is the highest paying certificate in the technological industry today.
Check Highest Paying Certification and Project Management Professional PMP Salary.

Eligibility
To apply for the PMP, you need to have either:
  • A four-year degree (bachelor’s or the global equivalent) and at least three years of project management experience, with 4,500 hours leading and directing projects and 35 hours of project management education.

  • OR

  • A secondary diploma (high school or the global equivalent) with at least five years of project management experience, with 7,500 hours leading and directing projects and 35 hours of project management education.
Please see Project Management Professional PMP

What Next?
I recommend that you start by taking the membership of PMI and your local PMI Chapter. For instance if you are based out of Mumbai you can take the membership of PMI and then the membership of the PMI Mumbai Chapter. As the proverb goes Show me a man's companions, and I will tell you what the man is. What better way to start your journey to become a project manager than by getting into the company of some!
The benefits are manifold, you start by getting a discount in the exam fees as PMI members, you also get access to online resources and PMI online communities of practice. Local chapters like Mumbai also provide resources like libraries and mentor programmes to its members.
In case you have not had 35 hours of project management training in your formal education you can take the 35 hours of project management education (one of the mandatory requirements for taking the PMI exam see Eligibility above) from any PMI Registered Education provider. Some local chapters like the PMI Mumbai Chapter provide this training to its members at a discounted rate. The fees for this programme from a PMI REP varies from INR 10,000/- to INR 15,000/- to the best of my knowledge.
Since this is only a 4 day training programme where you are introduced to the PMBOK (Project Management Body of Knowledge) I recommend that you familiarize yourself with the PMBOK before attending the training programme to make the most of it.
Apart from the PMBOK I strongly recommend that you also go through
  1. The PMP Exam: How to Pass on Your First Try, Fourth Edition by Andy Crowe
  2. PMP Exam Prep, Seventh Edition: by Rita Mulcahy
Currently the PMP test is based on the 4th edition of PMBOK.

Applying for the exam
The last hour of the above training by REPs usually covers how to fill the application form for the PMP exam. Some of the applications are randomly picked up for audit, in which case you have to submit hard copies of the application form signed by the references.
The test is online and held at select prometric centres.

Other
There are many groups online that you may join to help you prepare better.
Best of luck with your PMP preparations.

सोमवार, फेब्रुवारी ०६, २०१२

Rails include v/s joins

ही पोस्ट दिग्गज हितेश रावल यांच्या personal blog Hello World मधून घेतली आहे.

:include व :joins , एकप्रकारे हे दोन्ही, सारखेच आहेत कारण दोघांचा वापर एकाच (single) query मार्फत संबंधित table value शोधण्यास होतो. त्यामुळे बर्याचदा आपण या दुविधेत सापडतो कि :include वापरावे कि :joins . या करता एक अतिशय उपयुक्त असे Railscats आहे. या सोबत 'active record चे find method' हा लेख सुद्धा उपयुक्त ठरेल.
यांचावरून मी पुढीलप्रमाणे निष्कर्ष काढला आहे जो हा निर्णय घेण्यास मदतगार ठरेल.

:include
  • associations' वर 'eager loading' गोवते.
  • हे सर्व क्लास रेकॉर्ड (class record) किंवा object attribute  प्राप्त करून मेमोरी मध्ये ठेवते.
  • हे संबंधित असे सर्व 'object attributes' एका 'select' ऑप्शन मार्फत प्राप्त करते.
  • हे संबंधित 'object attribute' view वर दर्शविण्यास उपयुक्त ठरते. 
  • default म्हणून हे LEFT OUTER JOIN चा वापर करते, जे table मधील सर्व रेकॉर्ड दाखवते,
उदाहरणार्थ:
  • :include हे eager -loading करते. यामुळे जेव्हा आपण user रेकॉर्ड प्राप्त करायचा प्रयत्न करू, तेव्हा दुसरी /वेगळी query नाही बनणार.

:joins
  • हे प्रत्यक्षपणे INNER JOIN चा वापर करते जे association नसलेले rows प्राप्त करते.
  • याचा वापर association names  ना  विविध प्रकारे join करण्याकरता आणि संबंधित tables ना join करण्याकरता होतो.
  • संबंधित object attribute values प्राप्त करण्यकरीता प्रत्येक वेळेला हे वेगळ्या query ची निर्मिती करते.
उदाहरणार्थ:

  • :joins eager-loading करत नाही. यामुळे जेव्हा आपण comment पासून user रेकॉर्ड  प्राप्त करायचं प्रयत्न करू, तेव्हा हे एक वेगळी sql query उभार.

The original post can be viewed on Hitesh Rawal's personal blog Hello World! as Rails include v/s joins.

शनिवार, फेब्रुवारी ०४, २०१२

Rails application मध्ये data sequencing (Sequencing data in rails application)

असे खुप सारे plugins आहेत जे data sequencing साठी वापरले जातात. काहीतरी सारखाच जे jQuery librabry बरोबर वापरल आहे.
Single Table Inheritence असल्याचे गृहीत धरु ज्यामध्ये १५ पेक्षा जास्त types आसतिल. म्हणजेच १५ पेक्षा जास्त inherited modules आणि ह्या साठी आसे पण गृहीत धरु की sequence करून एक column असेल.
आता समजा views मध्ये आपल्याला buttons लावायचे असतील तर एवढ्या साऱ्या changes करावे लागतील आणि जर पुढे जाउन नविन views आले तर मग त्याचे styling आणि अजुन काही घटक लक्षात राहणार शक्य नाही.
मग मी विचार केला की jQuery वापरयाची.

Controller :
# reset sequence ही action javascript ajax function वापरून call केली आहे.
# हा Js function client id , model type ( constant ) आणि recods चा array आणि index हे parameters constant update करायला pass केले आहेत. 
def reset_sequence
  model_type = params[:model_type]
  paramssequences = params[:sequences]
  clientid = params[:client_id].to_i
  paramssequences.each do |sequences|
    sequences.each do |sequence_array|
      sequence_record = sequence_array.split(",")
      id = sequence_record[0].to_i
      sequence = sequence_record[1].to_i
      object = model_type.singularize.camelize.constantize
      object.update_all({:sequence => sequence}, {:id => id, :client_id => clientid})
    end
  end
  respond_to do |format|
  format.js {
    render :update do |page|
      # जर हा block काढला तर missing template चा error येऊ शकतो. 
    end
  }
  end
end 

Routes :
reset_sequence

View :
  <table id="first_sub_types">
  <tbody>
  <tr>
    <th>Sequence</th>
    <th>Name</th>
    <th>Edit</th>
  </tr>
  <% first_sub_types.each do |subtype| %>
  <tr>
    <td><%= subtype.sequence %></td>
    <td><%= subtype.name %></td>
    <td><%= link_to "Edit", edit_first_sub_type_path(subtype.id) %></td>
  </tr>
  <% end %>
  </tbody>
  </table>

 <script type="text/javascript">  
    fetch_data("FirstSubType", 3, "first_sub_types")
  </script>  

Javascript :
sequencing.js नावाची नवी file बनवली.
Sequnce.js :
fetch_data( modelType, clientID, divID ) नावाचे सर्वात पाहिले function बनवले.
ज्या views मध्ये sequencing ची गरज आहे अशा views मधून buttons द्वारे हे call केले जाइल.
modeltype उदारणार्थ ("FirstSubType", 3, "first_sub_types") पाठवले जात आहे.                

/*
* fetch_data function द्वारे आपण id आणि table चे नाव jquery object मध्ये convert करणार.
* हेच build_html function call करेल created, model type(which model to be called), company id and divid असे objects वेगले pass करून.
*/
function fetch_data( modelType, clientID, divID ){
    var obj = jQuery(divID);
    build_html( obj, modelType, clientID, divID );
  }

आपण आताच काही variables pass केले view मधून आणि build_html हे function call केले.

/*
* हे function फक्त fetch_data() ह्या function द्वारे call करता येइल.
* build_html सर्वात पाहिले object चा tag कुठला आहे हे check करेल.                 will first check the object's tag name by jquery function .is() and based on this checkIfobject will be assigned a value.
* This assigned value will be used for sorting <td> OR <li> OR <option>.
* After checking the html tag the objects width is changed to fit the buttons on the right side.
* At the end loopingList() is called
*/
function build_html( obj, modelType, clientID, divID ){
    var checkIfobject;    

    if(obj.is("table")){
        checkIfobject = "TaBle"
    }else if(obj.is("ul")){
        checkIfobject = "UL"
    }else if(obj.is("select")){
        checkIfobject = "SelEct"
    }    

    var trheight = jQuery(obj).children().children('tr.bg1').height()
    var tdheight = (parseInt(trheight) * (jQuery(obj).children().children('tr').length-1)) + jQuery(obj).children().children('tr:first').height()
    jQuery(obj).after("<table cellpadding="0" cellspacing="0" id="setter" style="float: left;"><tbody><tr><th align="center" style="height: "+tdheight+"px;" valign="middle"> <input id="upbutton" name="upbutton" type="button" value=" ↑ " /> <br /> <input id="downbutton" name="downbutton" type="button" value=" ↓ " /> <input disabled="disabled" id="setbutton" name="setbutton" onclick="sendRequest( \""+checkIfobject+"\", \""+modelType+"\", \""+clientID+"\", \""+divID+"\" )" style="color: grey;" type="button" value="Set" /> </th></tr> </tbody></table>")

    var setterwidth = ( 100 * parseFloat(jQuery('#setter').css('width')) / parseFloat(jQuery('#setter').parent().css('width')) );
    var tblewidth = (99.7-setterwidth)
    jQuery(obj).css({
        "width" : tblewidth+"%",
        "float" : "left"
    });
    loopingList( obj, checkIfobject );
}
  
हे function add केलेल्या table च्या बाजूला नविन html बनवेल. पाहिले तर हा table डाव्या बाजूला shift होइल.          
आपण आता पर्यंत काही width लावली नाहीये जेणेकरून जी buttons ना width असेल तीच ह्याला पण apply होइल.
आपण object check केल्या मुले तो object UL आहे की SELECT हे आपल्यला समजेल आणि भविष्यामध्ये UL आणि SELECT objects पण वापरू शकू.
आता पर्यंत आपण जे केला ते फक्त styling साठी होता. पण आता मुख्य function call करुया loopingList( obj, checkIfobject );

/*
* हे function hidden field add करेल जे data indexing ला मदत करेल.          
* check_button() सर्वात शेवटी add केले आहे.
*/
function loopingList( obj, checkIfobject ){
    var list, mxLength;
    switch( checkIfobject ){
        case "TaBle":
            list = obj.children().children('tr');
            mxLength = list.length-1
            break;
        case "UL":
            list = obj.children('li');
            break;
        case "SelEct":
            list = obj.children('option');
            break;
    }

    list.each(function( index ) {
        var listitem = this;
        var jListitem = jQuery(listitem);        

        jListitem.attr('onClick', "updateList(this)");
        jListitem.children('td:first').append("<input class="supportField" id="hidden_"+index+"" type="hidden" value=""+index+"" />");
    });

    check_button( checkIfobject, mxLength );
}  

ह्याने प्रत्येक row ला १ Hidden field add होइल जे index/sequence ला update करेल.
पहिल्यांदा जेव्हा ही file call केली जाईल किंवा default, data चे index हे function स्वता set करेल.
पण हे नंतर modify होइल वेगळ्या function ने. जर database मध्ये काही values नसतील तर user ने click केल्या वर sequence default setting प्रमाणे change होइल.

/*
* हे function button click वर up and down sorting संभलते.
*/
function check_button( checkIfobject, mxLength ){
    jQuery('#upbutton').click(function(){
        var jListitem = jQuery(".selected_listitem");

        if( jListitem.length > 0 ){
            jQuery("#setbutton").removeAttr("disabled");
            jQuery("#setbutton").removeAttr("style");
            var prevlistitem = jListitem.prev();
            var prevlistitemIndex = prevlistitem.children("td:first").children("input.supportField").val();
            var jListitemIndex = jListitem.children("td:first").children("input.supportField").val();

            if( jListitemIndex == 1 ){ 
            }else{
                var innerhmtl = prevlistitem.html();
                prevlistitem.remove();
                jListitem.after(""+innerhmtl+"");
                jListitem.children("td:first").children("input.supportField").val(prevlistitemIndex);
                jListitem.next().children("td:first").children("input.supportField").val(jListitemIndex);
            }
        }else{
            alert("Select Record for sorting");
        }
    });

    jQuery('#downbutton').click(function(){
        var jListitem = jQuery(".selected_listitem");

        if( jListitem.length > 0 ){
            jQuery("#setbutton").removeAttr("disabled");
            jQuery("#setbutton").removeAttr("style");
            var nextlistitem = jListitem.next();
            var nextlistitemIndex = nextlistitem.children("td:first").children("input.supportField").val();
            var jListitemIndex = jListitem.children("td:first").children("input.supportField").val();

            if( jListitemIndex == mxLength ){
            }else{
                var innerhmtl = nextlistitem.html();
                nextlistitem.remove();
                jListitem.before(""+innerhmtl+"");
                jListitem.children("td:first").children("input.supportField").val(nextlistitemIndex);
                jListitem.prev().children("td:first").children("input.supportField").val(jListitemIndex);
            }
        }else{
            alert("Select Record for Sorting");
        }
    });

}
  
वरील function up and down sorting button च्या onclick वर चालते.
ह्या प्रमाणे असेही आहे की कमीतकमी १ row तरी selected असली पाहिजे नाहीतर alert message येइल.
सर्वात शेवटी प्रमुख function जे controller च्या  reset_sequence ह्या action ला ajax request पाठवली जाते.

function sendRequest( checkIfobject, modelType, clientID, divID ){
    var jListitem = jQuery(".selected_listitem");
    if( jListitem.length > 0 ){
      var list = jQuery(divID).children().children('tr');
      var sequences = []

      list.each(function(){
        var listitem = this;
        var jListitem = jQuery(listitem);
        var indNum = list.index(listitem);        

        if( indNum > 0 ){
            var id = jListitem.children("td:first").children("input.supportFieldID").val();
            var sequence = jListitem.children("td:first").children("input.supportField").val();
            sequences.push([id,sequence]);
        }
      });    

      jQuery.ajax({
        type: 'get',
        url: '/reset_sequence',
        data:
        {
            'sequences[]' : sequences,
            "model_type" : modelType,
            "client_id" : clientID
        },
        success: function(transform){
            //window.location.reload();
            window.location.href="/manage_company_utilities/"+modelType;
        }
      });
    }else{
            alert("Select Record for Sorting");
    }
}
  
The original post can be viewed on my personal blog as Sequencing data in rails application

गुरुवार, फेब्रुवारी ०२, २०१२

प्रस्तावना (Introduction)

हा आमचा पहिला पोस्ट. आजपासून तुमच्यासाठी आम्ही मराठीमध्ये अनेक Technical तसेच वेगळे विषय share करू. आतासाठी एवढच. परत भेटूया नवीन विषयांन बरोबर, काही दिग्गज व्यक्तींची मते आणि शब्द घेऊन.

This is our first post. From today we will be sharing technical as well as different subjects. Just this for now. We will meet again with new subjects, with experts opinions and words.