Changeset 103
- Timestamp:
- 20/01/09 12:23:13 (4 years ago)
- Location:
- trunk/luci/libs
- Files:
-
- 10 modified
-
cbi/luasrc/cbi.lua (modified) (8 diffs)
-
cbi/luasrc/view/cbi/tblsection.htm (modified) (2 diffs)
-
cbi/luasrc/view/cbi/ucisection.htm (modified) (1 diff)
-
core/luasrc/fs.lua (modified) (2 diffs)
-
core/luasrc/ip.lua (modified) (1 diff)
-
json/luasrc/json.lua (modified) (1 diff)
-
uci/luasrc/model/uci.lua (modified) (3 diffs)
-
uvl/luasrc/uvl.lua (modified) (7 diffs)
-
uvl/root/usr/bin/uvl (modified) (1 diff)
-
web/luasrc/dispatcher.lua (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/luci/libs/cbi/luasrc/cbi.lua
r4 r103 60 60 local upldir = "/lib/uci/upload/" 61 61 local cbidir = luci.util.libpath() .. "/model/cbi/" 62 63 assert(luci.fs.stat(cbimap) or luci.fs.stat(cbidir..cbimap..".lua"), 62 63 assert(luci.fs.stat(cbimap) or luci.fs.stat(cbidir..cbimap..".lua"), 64 64 "Model not found!") 65 65 66 66 local func, err = loadfile(cbimap) 67 67 if not func then … … 450 450 function Compound.parse(self, ...) 451 451 local cstate, state = 0, 0 452 452 453 453 for k, child in ipairs(self.children) do 454 454 cstate = child:parse(...) 455 455 state = (not state or cstate < state) and cstate or state 456 456 end 457 457 458 458 return state 459 459 end … … 473 473 transitor = transitor or self.transistor_linear 474 474 local state = {node=node, name=name, transitor=transitor} 475 475 476 476 assert(instanceof(node, Node), "Invalid node") 477 477 assert(not self.nodes[name], "Duplicate entry") 478 478 479 479 self.nodes[name] = state 480 480 self:append(state) 481 481 482 482 return state 483 483 end … … 502 502 local active = self:getactive() 503 503 assert(active, "Invalid state") 504 504 505 505 local cstate = active.node:parse() 506 506 self.active = active.transistor(self, active.node, cstate) 507 507 508 508 if not self.active then 509 509 return FORM_DONE … … 519 519 520 520 function Delegator.getactive(self) 521 return self:get(Map.formvalue(self, "cbi.delegated") 522 or (self.children[1] and self.children[1].name)) 521 return self:get(Map.formvalue(self, "cbi.delegated") 522 or (self.children[1] and self.children[1].name)) 523 523 end 524 524 … … 808 808 datasource.config = "table" 809 809 self.data = data 810 810 811 811 datasource.formvalue = Map.formvalue 812 812 datasource.formvaluetable = Map.formvaluetable … … 816 816 return data[section] and data[section][option] 817 817 end 818 818 819 819 function datasource.submitstate(self) 820 820 return Map.formvalue(self, "cbi.submit") … … 1496 1496 local valid = {} 1497 1497 for i, v in ipairs(value) do 1498 if luci.util.contains(self. vallist, v) then1498 if luci.util.contains(self.keylist, v) then 1499 1499 table.insert(valid, v) 1500 1500 end -
trunk/luci/libs/cbi/luasrc/view/cbi/tblsection.htm
r68 r103 29 29 <tr class="cbi-section-table-titles"> 30 30 <%- if not self.anonymous then -%> 31 <th> </th> 31 <%- if self.sectionhead then -%> 32 <th class="cbi-section-table-cell"><%=self.sectionhead%></th> 33 <%- else -%> 34 <th> </th> 35 <%- end -%> 32 36 <%- end -%> 33 37 <%- for i, k in pairs(self.children) do if not k.optional then -%> … … 43 47 <tr class="cbi-section-table-descr"> 44 48 <%- if not self.anonymous then -%> 45 <th></th> 49 <%- if self.sectiondesc then -%> 50 <th class="cbi-section-table-cell"><%=self.sectiondesc%></th> 51 <%- else -%> 52 <th></th> 53 <%- end -%> 46 54 <%- end -%> 47 55 <%- for i, k in pairs(self.children) do if not k.optional then -%> -
trunk/luci/libs/cbi/luasrc/view/cbi/ucisection.htm
r68 r103 13 13 14 14 -%> 15 16 <%- 17 if type(self.hidden) == "table" then 18 for k, v in pairs(self.hidden) do 19 -%> 20 <input type="hidden" id="cbid.<%=self.config%>.<%=section%>.<%=k%>" name="cbid.<%=self.config%>.<%=section%>.<%=k%>" value="<%=luci.util.pcdata(v)%>" /> 21 <%- 22 end 23 end 24 %> 15 25 16 26 <% self:render_children(section, scope or {}) %> -
trunk/luci/libs/core/luasrc/fs.lua
r4 r103 55 55 56 56 --- Checks wheather the given path exists and points to a regular file. 57 -- @param filename String containing the path of the file to read57 -- @param filename String containing the path of the file to test 58 58 -- @return Boolean indicating wheather given path points to regular file 59 59 function isfile(filename) 60 60 return posix.stat(filename, "type") == "regular" 61 end 62 63 --- Checks wheather the given path exists and points to a directory. 64 -- @param dirname String containing the path of the directory to test 65 -- @return Boolean indicating wheather given path points to directory 66 function isdirectory(dirname) 67 return posix.stat(dirname, "type") == "directory" 61 68 end 62 69 … … 130 137 end 131 138 139 --- Set the last modification time of given file path in Unix epoch format. 140 -- @param path String containing the path of the file or directory to read 141 -- @param mtime Last modification timestamp 142 -- @param atime Last accessed timestamp 143 -- @return 0 in case of success nil on error 144 -- @return String containing the error description (if any) 145 -- @return Number containing the os specific errno (if any) 146 utime = posix.utime 147 132 148 --- Return the last element - usually the filename - from the given path with 133 149 -- the directory component stripped. -
trunk/luci/libs/core/luasrc/ip.lua
r4 r103 66 66 67 67 elseif type(x) == "table" then 68 list = x68 list = { unpack(x) } 69 69 end 70 70 -
trunk/luci/libs/json/luasrc/json.lua
r4 r103 500 500 ['{'] = Decoder.parse_object 501 501 } 502 503 504 --- Create a new Active JSON-Decoder. 505 -- @class function 506 -- @name ActiveDecoder 507 -- @param customnull Use luci.json.null instead of nil for decoding null 508 -- @return Active JSON-Decoder 509 ActiveDecoder = util.class(Decoder) 510 511 function ActiveDecoder.__init__(self, source, customnull) 512 Decoder.__init__(self, customnull) 513 self.source = source 514 self.chunk = nil 515 getmetatable(self).__call = self.get 516 end 517 518 519 --- Fetches one JSON-object from given source 520 -- @return Decoded object 521 function ActiveDecoder.get(self) 522 local chunk, src_err, object 523 if not self.chunk then 524 chunk, src_err = self.source() 525 else 526 chunk = self.chunk 527 end 528 529 self.chunk, object = self:dispatch(chunk, src_err, true) 530 return object 531 end 532 533 534 function ActiveDecoder.fetch(self) 535 local chunk, src_err = self.source() 536 assert(chunk or not src_err, src_err) 537 return chunk 538 end -
trunk/luci/libs/uci/luasrc/model/uci.lua
r4 r103 62 62 function Cursor.delete_all(self, config, stype, comparator) 63 63 local del = {} 64 64 65 65 if type(comparator) == "table" then 66 66 local tbl = comparator … … 70 70 return false 71 71 end 72 end 72 end 73 73 return true 74 74 end 75 75 end 76 76 77 77 local function helper (section) 78 78 … … 125 125 end 126 126 127 --- Get a boolean option and return it's value as true or false. 128 -- @param config UCI config 129 -- @param section UCI section name 130 -- @param option UCI option 131 -- @return Boolean 132 function Cursor.get_bool(self, ...) 133 local val = self:get(...) 134 return ( val == "1" or val == "true" or val == "yes" or val == "on" ) 135 end 136 127 137 --- Get an option or list and return values as table. 128 138 -- @param config UCI config -
trunk/luci/libs/uvl/luasrc/uvl.lua
r4 r103 68 68 -- @name UVL 69 69 -- @param schemedir Path to the scheme directory (optional) 70 -- @param configdir Override config directory (optional) 70 71 -- @return Instance object 71 72 UVL = util.class() 72 73 73 function UVL.__init__( self, schemedir )74 function UVL.__init__( self, schemedir, configdir ) 74 75 self.schemedir = schemedir or default_schemedir 76 self.configdir = configdir 75 77 self.packages = { } 76 78 self.beenthere = { } … … 947 949 end 948 950 949 function uvlitem._loadconf(self, co, c )951 function uvlitem._loadconf(self, co, c, configdir) 950 952 co = co or self._configcache 951 953 if not co then 952 954 local err 953 co, err = uci.cursor( ):get_all(c)955 co, err = uci.cursor(configdir):get_all(c) 954 956 955 957 if err then … … 984 986 self.cref = { c } 985 987 self.sref = { c } 986 self.c = self:_loadconf(co, c )988 self.c = self:_loadconf(co, c, scheme.configdir) 987 989 self.s = scheme 988 990 self.t = TYPE_SCHEME … … 1048 1050 c, co = co, nil 1049 1051 end 1050 1051 1052 self.cref = { c } 1052 1053 self.sref = { c } 1053 self.c = self:_loadconf(co, c )1054 self.c = self:_loadconf(co, c, scheme.configdir) 1054 1055 self.s = scheme 1055 1056 self.t = TYPE_CONFIG … … 1099 1100 self.cref = { c, s } 1100 1101 self.sref = { c, co and co[s] and co[s]['.type'] or s } 1101 self.c = self:_loadconf(co, c )1102 self.c = self:_loadconf(co, c, scheme.configdir) 1102 1103 self.s = scheme 1103 1104 self.t = TYPE_SECTION … … 1150 1151 self.cref = { c, s, o } 1151 1152 self.sref = { c, co and co[s] and co[s]['.type'] or s, o } 1152 self.c = self:_loadconf(co, c )1153 self.c = self:_loadconf(co, c, scheme.configdir) 1153 1154 self.s = scheme 1154 1155 self.t = TYPE_OPTION … … 1203 1204 self.cref = { c, s, o, v } 1204 1205 self.sref = { c, co and co[s] and co[s]['.type'] or s, o, v } 1205 self.c = self:_loadconf(co, c )1206 self.c = self:_loadconf(co, c, scheme.configdir) 1206 1207 self.s = scheme 1207 1208 self.t = TYPE_ENUM -
trunk/luci/libs/uvl/root/usr/bin/uvl
r4 r103 201 201 202 202 local uvl = luci.uvl.UVL( 203 type(options.schemedir) == "string" and options.schemedir 203 type(options.schemedir) == "string" and options.schemedir, 204 type(options.configdir) == "string" and options.configdir 204 205 ) 205 206 -
trunk/luci/libs/web/luasrc/dispatcher.lua
r16 r103 167 167 if c and c.leaf then 168 168 for j=n+1, #request do 169 table.insert(args, request[j]) 169 args[#args+1] = request[j] 170 freq[#freq+1] = request[j] 170 171 end 171 172 end … … 247 248 end 248 249 249 if c and (c.index or type(c.target) == "function") then 250 local target = nil 251 if c then 252 if type(c.target) == "function" then 253 target = c.target 254 elseif type(c.target) == "table" then 255 target = c.target.target 256 end 257 end 258 259 if c and (c.index or type(target) == "function") then 250 260 ctx.dispatched = c 251 261 ctx.requested = ctx.requested or ctx.dispatched … … 254 264 if c and c.index then 255 265 local tpl = require "luci.template" 256 tpl.render "indexer" 257 return true 258 end 259 260 if c and type(c.target) == "function" then 266 if util.copcall(tpl.render, "indexer", {}) then 267 return true 268 end 269 end 270 271 if type(target) == "function" then 261 272 util.copcall(function() 262 local oldenv = getfenv( c.target)273 local oldenv = getfenv(target) 263 274 local module = require(c.module) 264 275 local env = setmetatable({}, {__index= … … 268 279 end}) 269 280 270 setfenv( c.target, env)281 setfenv(target, env) 271 282 end) 272 283 273 c.target(unpack(args)) 284 if type(c.target) == "table" then 285 target(c.target, unpack(args)) 286 else 287 target(unpack(args)) 288 end 274 289 else 275 290 error404() … … 518 533 end 519 534 535 536 local function _call(self, ...) 537 if #self.argv > 0 then 538 return getfenv()[self.name](unpack(self.argv), ...) 539 else 540 return getfenv()[self.name](...) 541 end 542 end 543 520 544 --- Create a function-call dispatching target. 521 545 -- @param name Target function of local controller 522 546 -- @param ... Additional parameters passed to the function 523 547 function call(name, ...) 524 local argv = {...} 525 return function(...) 526 if #argv > 0 then 527 return getfenv()[name](unpack(argv), ...) 528 else 529 return getfenv()[name](...) 530 end 531 end 548 return {type = "call", argv = {...}, name = name, target = _call} 549 end 550 551 552 local _template = function(self, ...) 553 require "luci.template".render(self.view) 532 554 end 533 555 … … 535 557 -- @param name Template to be rendered 536 558 function template(name) 537 return function() 538 require("luci.template") 539 luci.template.render(name) 540 end 559 return {type = "template", view = name, target = _template} 560 end 561 562 563 local function _cbi(self, ...) 564 local cbi = require "luci.cbi" 565 local tpl = require "luci.template" 566 local http = require "luci.http" 567 568 local config = self.config or {} 569 local maps = cbi.load(self.model, ...) 570 571 local state = nil 572 573 for i, res in ipairs(maps) do 574 if config.autoapply then 575 res.autoapply = config.autoapply 576 end 577 local cstate = res:parse() 578 if not state or cstate < state then 579 state = cstate 580 end 581 end 582 583 if config.on_valid_to and state and state > 0 and state < 2 then 584 http.redirect(config.on_valid_to) 585 return 586 end 587 588 if config.on_changed_to and state and state > 1 then 589 http.redirect(config.on_changed_to) 590 return 591 end 592 593 if config.on_success_to and state and state > 0 then 594 http.redirect(config.on_success_to) 595 return 596 end 597 598 if config.state_handler then 599 if not config.state_handler(state, maps) then 600 return 601 end 602 end 603 604 local pageaction = true 605 local cancelaction = false 606 http.header("X-CBI-State", state or 0) 607 luci.template.render("cbi/header", {state = state}) 608 for i, res in ipairs(maps) do 609 res:render() 610 if res.pageaction == false then 611 pageaction = false 612 end 613 if res.cancelaction == true then 614 cancelaction = true 615 end 616 end 617 luci.template.render("cbi/footer", {pageaction=pageaction, cancelaction=cancelaction, state = state, autoapply = config.autoapply}) 541 618 end 542 619 … … 544 621 -- @param model CBI model to be rendered 545 622 function cbi(model, config) 546 config = config or {} 547 return function(...) 548 require("luci.cbi") 549 require("luci.template") 550 local http = require "luci.http" 551 552 maps = luci.cbi.load(model, ...) 553 554 local state = nil 555 556 for i, res in ipairs(maps) do 557 if config.autoapply then 558 res.autoapply = config.autoapply 559 end 560 local cstate = res:parse() 561 if not state or cstate < state then 562 state = cstate 563 end 564 end 565 566 if config.on_valid_to and state and state > 0 and state < 2 then 567 luci.http.redirect(config.on_valid_to) 568 return 569 end 570 571 if config.on_changed_to and state and state > 1 then 572 luci.http.redirect(config.on_changed_to) 573 return 574 end 575 576 if config.on_success_to and state and state > 0 then 577 luci.http.redirect(config.on_success_to) 578 return 579 end 580 581 if config.state_handler then 582 if not config.state_handler(state, maps) then 583 return 584 end 585 end 586 587 local pageaction = true 588 local cancelaction = false 589 http.header("X-CBI-State", state or 0) 590 luci.template.render("cbi/header", {state = state}) 591 for i, res in ipairs(maps) do 592 res:render() 593 if res.pageaction == false then 594 pageaction = false 595 end 596 if res.cancelaction == true then 597 cancelaction = true 598 end 599 end 600 luci.template.render("cbi/footer", {pageaction=pageaction, cancelaction=cancelaction, state = state, autoapply = config.autoapply}) 601 end 623 return {type = "cbi", config = config, model = model, target = _cbi} 624 end 625 626 627 local function _arcombine(self, ...) 628 local argv = {...} 629 local target = #argv > 0 and self.targets[2] or self.targets[1] 630 setfenv(target.target, self.env) 631 target:target(unpack(argv)) 632 end 633 634 --- Create a combined dispatching target for non argv and argv requests. 635 -- @param trg1 Overview Target 636 -- @param trg2 Detail Target 637 function arcombine(trg1, trg2) 638 return {type = "arcombine", env = getfenv(), target = _arcombine, targets = {trg1, trg2}} 639 end 640 641 642 local function _form(self, ...) 643 local cbi = require "luci.cbi" 644 local tpl = require "luci.template" 645 local http = require "luci.http" 646 647 local maps = luci.cbi.load(self.model, ...) 648 local state = nil 649 650 for i, res in ipairs(maps) do 651 local cstate = res:parse() 652 if not state or cstate < state then 653 state = cstate 654 end 655 end 656 657 http.header("X-CBI-State", state or 0) 658 tpl.render("header") 659 for i, res in ipairs(maps) do 660 res:render() 661 end 662 tpl.render("footer") 602 663 end 603 664 … … 605 666 -- @param model CBI form model tpo be rendered 606 667 function form(model) 607 return function(...) 608 require("luci.cbi") 609 require("luci.template") 610 local http = require "luci.http" 611 612 maps = luci.cbi.load(model, ...) 613 614 local state = nil 615 616 for i, res in ipairs(maps) do 617 local cstate = res:parse() 618 if not state or cstate < state then 619 state = cstate 620 end 621 end 622 623 http.header("X-CBI-State", state or 0) 624 luci.template.render("header") 625 for i, res in ipairs(maps) do 626 res:render() 627 end 628 luci.template.render("footer") 629 end 630 end 668 return {type = "cbi", model = model, target = _form} 669 end
