brew install hudochenkov/sshpass/sshpass
sshpass -p password ssh -p port user@xxxx.xxxx.xxxx.xxxx
在superset => templates => appbuilder 文件夹下找到 navbar.html 如果没有可对应新建,navbar.html内容如下
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
{% set menu = appbuilder.menu %} {% set languages = appbuilder.languages %} {% set WARNING_MSG = appbuilder.app.config.get('WARNING_MSG') %} {% set app_icon_width = appbuilder.app.config.get('APP_ICON_WIDTH', 126) %} {% set logo_target_path = appbuilder.app.config.get('LOGO_TARGET_PATH') or '/profile/{}/'.format(current_user.username) %} <div class="navbar navbar-static-top {{ menu.extra_classes }}" role="navigation"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="{{ '/superset' + logo_target_path if current_user.username is defined else '#' }}"> <img width="{{ app_icon_width }}" src="{{ appbuilder.app_icon }}" alt="{{ appbuilder.app_name }}" /> </a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> {% if WARNING_MSG %} <li class="alert alert-danger"> {{ WARNING_MSG | safe }} </li> {% endif %} {% include 'appbuilder/navbar_menu.html' %} </ul> <ul class="nav navbar-nav navbar-right"> {% include 'appbuilder/navbar_right.html' %} </ul> </div> </div> </div> <script> // Highlight the navbar menu const menus = document.querySelectorAll('.nav.navbar-nav li') for (const menu of menus.values()) { const menuParent = menu.parentNode && menu.parentNode.parentNode const parentClasses = menuParent.getAttribute('class') const classes = menu.getAttribute('class') const as = menu.querySelectorAll('a') for (const a of as.values()) { const href = a.getAttribute('href') let path = location.pathname if (path.indexOf(href) > -1) { menu.setAttribute('class', `${classes} active`) if (parentClasses.indexOf('dropdown') > -1) { menuParent.setAttribute('class', `${parentClasses} active`) } else { menuParent.setAttribute('class', `${parentClasses}`) } } else { menu.setAttribute('class', `${classes}`) } } } </script> |
访问者模式(Visitor Pattern)
|
1 2 3 |
定义:使用一个访问者类,改变元素类的执行算法。通过这种方式,元素的执行算法可以随着访问者改变而改变。 目的:将数据结构与数据操作分离。 场景:您在朋友家做客,您是访问者,朋友接受您的访问,您通过朋友的描述,然后对朋友的描述做出一个判断,这就是访问者模式。 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
// 元素:圆形 class Circle { constructor(radius) { this.radius = radius } accept(visitor) { return visitor.visitCircle(this) } } // 元素:矩形 class Rectangle { constructor(width, height) { this.width = width this.height = height } accept(visitor) { return visitor.visitRectangle(this) } } // 访问者:计算面积 class AreaVisitor { visitCircle(circle) { return Math.PI * circle.radius ** 2 } visitRectangle(rectangle) { return rectangle.width * rectangle.height } } // 访问者:计算周长 class PerimeterVisitor { visitCircle(circle) { return 2 * Math.PI * circle.radius } visitRectangle(rectangle) { return 2 * (rectangle.width + rectangle.height) } } // 使用 const rectangle = new Rectangle(3, 4) const circle = new Circle(1) const areaVisitor = new AreaVisitor() const perimeterVisitor = new PerimeterVisitor() console.log(rectangle.accept(areaVisitor)) // 12 console.log(rectangle.accept(perimeterVisitor)) // 14 console.log(circle.accept(areaVisitor)) // 约 3.14 console.log(circle.accept(perimeterVisitor)) // 约 6.28 |
解释器模式(Interpreter Pattern)
|
1 2 3 |
定义:提供了评估语言的语法或表达式的方式。 目的:对于一些固定文法构建一个解释句子的解释器。 场景:编译器、运算表达式计算。 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
// 基础表达式:判断是否包含关键词 class Keyword { constructor(word) { this.word = word } interpret(context) { return context.includes(this.word) } } // 或表达式:满足任意一个条件 class Or { constructor(left, right) { this.left = left this.right = right } interpret(context) { return this.left.interpret(context) || this.right.interpret(context) } } // 与表达式:必须同时满足两个条件 class And { constructor(left, right) { this.left = left this.right = right } interpret(context) { return this.left.interpret(context) && this.right.interpret(context) } } // 构建规则:(John OR Robert) AND Married const rule = new And( new Or( new Keyword('John'), new Keyword('Robert') ), new Keyword('Married') ) // 解释输入,得到结果 console.log(rule.interpret('John Married')) // true console.log(rule.interpret('Robert Married')) // true console.log(rule.interpret('John')) // false console.log(rule.interpret('Julie Married')) // false |
中介者模式(Mediator Pattern)
|
1 2 3 |
定义:用来降低多个对象和类之间的通信复杂性。 目的:用一个中介对象来封装一系列的对象交互,中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。 场景:MVC框架中的控制器C就是模型M和识图V的中介者。 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
// 中介者:统一协调跑道 const tower = { currentPlane: null, requestLanding(plane) { if (this.currentPlane) { console.log(`${plane.name}:跑道被占用,请等待`) return } this.currentPlane = plane plane.land() }, releaseRunway(plane) { if (this.currentPlane === plane) { this.currentPlane = null } } } // 参与者:只与塔台通信,不直接联系其他飞机 class Plane { constructor(name, tower) { this.name = name this.tower = tower } requestLanding() { this.tower.requestLanding(this) } land() { console.log(`${this.name}:开始降落`) } leaveRunway() { this.tower.releaseRunway(this) } } const planeA = new Plane('飞机A', tower) const planeB = new Plane('飞机B', tower) planeA.requestLanding() // 飞机A:开始降落 planeB.requestLanding() // 飞机B:跑道被占用,请等待 planeA.leaveRunway() planeB.requestLanding() // 飞机B:开始降落 |
Github地址:https://github.com/skillnull/Design-Mode-Example[……]
职责链模式(Chain of Responsibility Pattern)
|
1 2 3 |
定义:为请求创建了一个接收者对象的链。 目的:避免请求发送者与接收者耦合在一起,让多个对象都有可能接收请求,将这些对象连接成一条链,并且沿着这条链传递请求,直到有对象处理它为止。 场景:红楼梦中的"击鼓传花"。 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
class Approver { constructor(name, limit) { this.name = name this.limit = limit this.next = null } processRequest(request) { // 自己能处理,就处理并结束 if (request.amount < this.limit) { console.log(`${this.name}批准采购:${request.productName}`) return } // 自己不能处理,交给下一级 if (this.next) { return this.next.processRequest(request) } // 已经到达链尾,仍然无法处理 console.log(`采购金额超出审批权限:${request.productName}`) } } // 创建审批者 const manager = new Approver('经理', 10000) const vicePresident = new Approver('副总', 25000) const president = new Approver('总经理', 100000) // 连接职责链:经理 → 副总 → 总经理 manager.next = vicePresident vicePresident.next = president // 所有请求都从链头提交 manager.processRequest({ amount: 4000, productName: '电话' }) manager.processRequest({ amount: 10000, productName: '软件' }) manager.processRequest({ amount: 40000, productName: '电脑' }) manager.processRequest({ amount: 200000, productName: '服务器' }) |
输出:
经理批准采购:电话
副总批准采购:软件
总经理批准采购:电脑
采[……]
命令模式(Command Pattern)
|
1 2 3 |
定义:请求以命令的形式包裹在对象中,并传给调用对象。调用对象寻找可以处理该命令的合适的对象,并把该命令传给相应的对象,该对象执行命令。 目的:将一个请求封装成一个对象,从而使您可以用不同的请求对客户进行参数化。 场景:在一个快餐店,用户向服务员点餐。服务员将用户的需求记录在清单上。 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// 1. 接收者:真正做事 const light = { turnOn() { console.log('灯亮了') } } // 2. 命令:封装“让这盏灯打开”的请求 class TurnOnCommand { constructor(light) { this.light = light } execute() { this.light.turnOn() } } // 3. 调用者:只负责执行命令 const remote = { press(command) { command.execute() } } // 使用 const command = new TurnOnCommand(light) remote.press(command) // 灯亮了 |